Class: Configurethis::MockConfiguration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ MockConfiguration

Returns a new instance of MockConfiguration.



5
6
7
8
# File 'lib/configurethis/mock_configuration.rb', line 5

def initialize(values)
  @path = "<mocked_configuration>"
  @mock_values = values
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/configurethis/mock_configuration.rb', line 16

def [](key)
  @values ||= load_configuration
  val = @values.fetch(key)
  return ValueContainer.new(val, path) if val.is_a?(Hash)
  val
rescue ::IndexError
  raise "'#{key}' is not configured in #{path}"
end

#load_configurationObject



25
26
27
# File 'lib/configurethis/mock_configuration.rb', line 25

def load_configuration
  @mock_values
end

#root=(key) ⇒ Object



10
11
12
13
14
# File 'lib/configurethis/mock_configuration.rb', line 10

def root=(key)
  @values = load_configuration.fetch(key)
rescue ::IndexError
  raise "'#{key}' is not configured in #{path}"
end