module Honeybadger::Config::Env

Constants

ARRAY_VALUES
CONFIG_KEY
CONFIG_MAPPING
IGNORED_TYPES

Public Class Methods

cast_value(value, type = String) click to toggle source
# File lib/honeybadger/config/env.rb, line 25
def self.cast_value(value, type = String)
  v = value.to_s

  if type == Boolean
    !!(v =~ /\A(true|t|1)\z/i)
  elsif type == Array
    v.split(ARRAY_VALUES).map(&method(:cast_value))
  elsif type == Integer
    v.to_i
  elsif type == Float
    v.to_f
  else
    v
  end
end
new(env = ENV) click to toggle source
# File lib/honeybadger/config/env.rb, line 11
def self.new(env = ENV)
  hash = {}

  env.each_pair do |k,v|
    next unless k.match(CONFIG_KEY)
    next unless config_key = CONFIG_MAPPING[$1]
    type = OPTIONS[config_key][:type]
    next if IGNORED_TYPES.include?(type)
    hash[config_key] = cast_value(v, type)
  end

  hash
end