Class: Configurethis::ValueContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/configurethis/value_container.rb

Instance Method Summary collapse

Constructor Details

#initialize(original, config_path) ⇒ ValueContainer

Returns a new instance of ValueContainer.



3
4
5
6
# File 'lib/configurethis/value_container.rb', line 3

def initialize(original, config_path)
  @original_value = original
  @config_path = config_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/configurethis/value_container.rb', line 12

def method_missing(method, *args)
  val = @original_value.fetch(method.to_s)
  return ValueContainer.new(val, @config_path) if val.is_a?(Hash)
  val
rescue KeyError => caught
  raise "Nested value '#{method.to_s}' is not configured in #{@config_path}"
end

Instance Method Details

#keysObject



8
9
10
# File 'lib/configurethis/value_container.rb', line 8

def keys
  @original_value.keys
end