Module: Honeybadger::Config::Env Private

Defined in:
lib/honeybadger/config/env.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

CONFIG_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\AHONEYBADGER_(.+)\Z/.freeze
CONFIG_MAPPING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Hash[DEFAULTS.keys.map {|k| [k.to_s.upcase.gsub(KEY_REPLACEMENT, '_'), k] }].freeze
ARRAY_VALUES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Regexp.new('\s*,\s*').freeze

Class Method Summary collapse

Class Method Details

.cast_value(value, type = String) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/honeybadger/config/env.rb', line 20

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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/honeybadger/config/env.rb', line 8

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]
    hash[config_key] = cast_value(v, OPTIONS[config_key][:type])
  end

  hash
end