Sha256: e00c5f79bc42a3828fc920fd3e3fd2248ac711e0c74486454b6d23eff63ebe5d

Contents?: true

Size: 919 Bytes

Versions: 24

Compression:

Stored size: 919 Bytes

Contents

module Honeybadger
  class Config
    module Env
      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 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

      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
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
honeybadger-4.3.1 lib/honeybadger/config/env.rb
honeybadger-4.3.0 lib/honeybadger/config/env.rb
honeybadger-4.2.2 lib/honeybadger/config/env.rb
honeybadger-4.2.1 lib/honeybadger/config/env.rb
honeybadger-4.2.0 lib/honeybadger/config/env.rb
honeybadger-4.1.0 lib/honeybadger/config/env.rb
honeybadger-4.0.0 lib/honeybadger/config/env.rb
honeybadger-3.3.1 lib/honeybadger/config/env.rb
honeybadger-3.4.0.beta1 lib/honeybadger/config/env.rb
honeybadger-3.3.0 lib/honeybadger/config/env.rb
honeybadger-3.2.0 lib/honeybadger/config/env.rb
honeybadger-3.2.0.beta1 lib/honeybadger/config/env.rb
honeybadger-3.1.2 lib/honeybadger/config/env.rb
honeybadger-3.1.1 lib/honeybadger/config/env.rb
honeybadger-3.1.0 lib/honeybadger/config/env.rb
honeybadger-3.0.2 lib/honeybadger/config/env.rb
honeybadger-3.0.1 lib/honeybadger/config/env.rb
honeybadger-3.0.0 lib/honeybadger/config/env.rb
honeybadger-3.0.0.beta6 lib/honeybadger/config/env.rb
honeybadger-3.0.0.beta5 lib/honeybadger/config/env.rb