Class: AppConfigLoader::ConfigWithIndifferentAccess
- Inherits:
-
Object
- Object
- AppConfigLoader::ConfigWithIndifferentAccess
- Includes:
- Enumerable
- Defined in:
- lib/app_config_loader/config_with_indifferent_access.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#get(key) ⇒ Object
(also: #[])
Get value for a specified config key.
-
#initialize(map, prefix = nil) ⇒ ConfigWithIndifferentAccess
constructor
A new instance of ConfigWithIndifferentAccess.
- #to_a ⇒ Object
Constructor Details
#initialize(map, prefix = nil) ⇒ ConfigWithIndifferentAccess
Returns a new instance of ConfigWithIndifferentAccess.
5 6 7 8 |
# File 'lib/app_config_loader/config_with_indifferent_access.rb', line 5 def initialize(map, prefix = nil) @config_map = map @prefix = prefix end |
Instance Method Details
#each(&block) ⇒ Object
40 41 42 |
# File 'lib/app_config_loader/config_with_indifferent_access.rb', line 40 def each(&block) @config_map.each(&block) end |
#get(key) ⇒ Object Also known as: []
Get value for a specified config key
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |
#to_a ⇒ Object
36 37 38 |
# File 'lib/app_config_loader/config_with_indifferent_access.rb', line 36 def to_a @config_map.to_a end |