class AppConfigLoader::ConfigWithIndifferentAccess
Public Class Methods
new(map, prefix = nil)
click to toggle source
# File lib/app_config_loader/config_with_indifferent_access.rb, line 5 def initialize(map, prefix = nil) @config_map = map @prefix = prefix end
Public Instance Methods
each(&block)
click to toggle source
# File lib/app_config_loader/config_with_indifferent_access.rb, line 40 def each(&block) @config_map.each(&block) end
get(key)
click to toggle source
Get value for a specified config key
@param [String] key app config key
@return the value for the key or another ConfigWithIndifferentAccess
; nil if there is no value at the key
@example Getting key value
app_config['some_service.host'] # => 'dev.someservice.com' app_config.get('some_service.host') # => 'dev.someservice.com'
# File lib/app_config_loader/config_with_indifferent_access.rb, line 19 def get(key) # append prefix to the key if needed target_key = @prefix ? "#{@prefix}.#{key}" : key.to_s # return either nil, the value or another ConfigWithIndifferentAccess depending on # what is at the key case (entry = @config_map[target_key]) when ConfigEntry entry.value when Hash self.class.new @config_map, target_key else nil end end
Also aliased as: []
to_a()
click to toggle source
# File lib/app_config_loader/config_with_indifferent_access.rb, line 36 def to_a @config_map.to_a end