class ElasticAPM::Config::Options::Option
@api private
def env_key
def env_key "ELASTIC_APM_#{key.upcase}" end
def initialize(
def initialize( key, value: nil, type: :string, default: nil, converter: nil ) @key = key @type = type @default = default @converter = converter set(value || default) end
def normalize(val)
def normalize(val) return if val.nil? if @converter return @converter.call(val) end case type when :string then val.to_s when :int then val.to_i when :float then val.to_f when :bool then normalize_bool(val) when :list then normalize_list(val) when :dict then normalize_dict(val) when :url then normalize_url(val) else # raise "Unknown options type '#{type.inspect}'" val end end
def normalize_bool(val)
def normalize_bool(val) return val unless val.is_a?(String) !%w[0 false].include?(val.strip.downcase) end
def normalize_dict(val)
def normalize_dict(val) return val unless val.is_a?(String) Hash[val.split(/[&,]/).map { |kv| kv.split('=') }] end
def normalize_list(val)
def normalize_list(val) return Array(val) unless val.is_a?(String) val.split(/[ ,]/) end
def normalize_url(val)
def normalize_url(val) val = val.to_s val.end_with?('/') ? val.chomp('/') : val end
def set(value)
def set(value) @value = normalize(value) end