Class: Configurethis::Configuration

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

Direct Known Subclasses

MockConfiguration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration_file) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
# File 'lib/configurethis/configuration.rb', line 7

def initialize(configuration_file)
  @path = File.join(ConfigurethisProperties.root_path, configuration_file)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



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

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



26
27
28
29
30
# File 'lib/configurethis/configuration.rb', line 26

def load_configuration
  File.open(path){ |f| ::YAML::load(f) }
rescue Exception => caught
  raise "Could not locate configuration file: #{path}"
end

#root=(key) ⇒ Object



11
12
13
14
15
# File 'lib/configurethis/configuration.rb', line 11

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