Class: SettingsHash
- Inherits:
-
ReadonlyHash
- Object
- Hash
- ReadonlyHash
- SettingsHash
- Defined in:
- lib/settings_hash.rb
Defined Under Namespace
Classes: SettingMissing
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path, namespace = nil) ⇒ SettingsHash
constructor
A new instance of SettingsHash.
Methods inherited from ReadonlyHash
Methods inherited from Hash
Constructor Details
#initialize(path, namespace = nil) ⇒ SettingsHash
Returns a new instance of SettingsHash.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/settings_hash.rb', line 7 def initialize(path, namespace=nil) raise "No settings file found: #{path}" unless File.exists?(path) settings = YAML.load_file(path) if namespace raise "No settings defined for #{namespace} in settings file: #{path}" unless settings[namespace] settings = settings[namespace] end super(settings.symbolize_keys) end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 |
# File 'lib/settings_hash.rb', line 19 def [](key) raise SettingMissing.new("No setting found for #{key}") unless has_key?(key) super end |