Sha256: aa633511646e79964244c3f046870f7845b5dd862beb4741987aeccbe20ed1e7

Contents?: true

Size: 993 Bytes

Versions: 25

Compression:

Stored size: 993 Bytes

Contents

module Honeybadger
  class Config
    class Env < ::Hash
      CONFIG_KEY = /\AHONEYBADGER_(.+)\Z/.freeze
      CONFIG_MAPPING = Hash[DEFAULTS.keys.map {|k| [k.to_s.upcase.gsub(KEY_REPLACEMENT, '_'), k] }].freeze
      ARRAY_VALUES = Regexp.new('\s*,\s*').freeze

      def initialize(env = ENV)
        env.each_pair do |k,v|
          next unless k.match(CONFIG_KEY)
          next if DISALLOWED_KEYS.include?(CONFIG_MAPPING[$1])
          self[CONFIG_MAPPING[$1] || $1.downcase.to_sym] = cast_value(v)
        end
      end

      private

      def cast_value(value)
        if value.match(ARRAY_VALUES)
          return value.split(ARRAY_VALUES).map(&method(:cast_value))
        end

        case value
        when /\Atrue\Z/
          true
        when /\Afalse\Z/
          false
        when /\Anil\Z/
          nil
        when /\A\d+\z/
          value.to_i
        when /\A\d+\.\d+\z/
          value.to_f
        else
          value.to_s
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
honeybadger-2.0.12 lib/honeybadger/config/env.rb
honeybadger-2.0.11 lib/honeybadger/config/env.rb
honeybadger-2.0.10 lib/honeybadger/config/env.rb
honeybadger-2.0.9 lib/honeybadger/config/env.rb
honeybadger-2.0.8 lib/honeybadger/config/env.rb
honeybadger-2.0.6 lib/honeybadger/config/env.rb
honeybadger-2.0.5 lib/honeybadger/config/env.rb
honeybadger-2.0.4 lib/honeybadger/config/env.rb
honeybadger-2.0.3 lib/honeybadger/config/env.rb
honeybadger-2.0.2 lib/honeybadger/config/env.rb
honeybadger-2.0.1 lib/honeybadger/config/env.rb
honeybadger-2.0.0 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.13 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.12 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.11 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.10 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.9 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.8 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.7 lib/honeybadger/config/env.rb
honeybadger-2.0.0.beta.6 lib/honeybadger/config/env.rb