Class: Configurethis::MockConfiguration
- Inherits:
-
Object
- Object
- Configurethis::MockConfiguration
- Defined in:
- lib/configurethis/mock_configuration.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(values) ⇒ MockConfiguration
constructor
A new instance of MockConfiguration.
- #load_configuration ⇒ Object
- #root=(key) ⇒ Object
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
#path ⇒ Object (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_configuration ⇒ Object
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 |