Class: RadSettings
- Inherits:
-
Hash
- Object
- Hash
- RadSettings
- Defined in:
- lib/rad_settings.rb
Class Method Summary collapse
- .[](hash) ⇒ Object
- .create_accessors! ⇒ Object
- .instance ⇒ Object
- .load ⇒ Object
- .load! ⇒ Object
- .namespace(value = nil) ⇒ Object
- .source(value = nil) ⇒ Object
- .to_hash ⇒ Object
Instance Method Summary collapse
Class Method Details
.[](hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rad_settings.rb', line 29 def [](hash) return instance[hash] unless hash.is_a?(Hash) res = super(hash) res.keys.each do |key| define_method key.to_s do value = self[key.to_s] || self[key.to_sym] value.is_a?(Hash) ? self.class[value] : value end end res end |
.create_accessors! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/rad_settings.rb', line 44 def create_accessors! instance.keys.each do |key| singleton_class.class_eval do define_method key.to_s do instance.send(key) end end end end |
.instance ⇒ Object
21 22 23 |
# File 'lib/rad_settings.rb', line 21 def instance @instance ||= load end |
.load ⇒ Object
25 26 27 |
# File 'lib/rad_settings.rb', line 25 def load self[YAML.load_file(source)[namespace]] end |
.load! ⇒ Object
15 16 17 18 19 |
# File 'lib/rad_settings.rb', line 15 def load! @instance = nil create_accessors! instance end |
.namespace(value = nil) ⇒ Object
11 12 13 |
# File 'lib/rad_settings.rb', line 11 def namespace(value = nil) @namespace ||= value end |
.source(value = nil) ⇒ Object
7 8 9 |
# File 'lib/rad_settings.rb', line 7 def source(value = nil) @source ||= value end |
.to_hash ⇒ Object
54 55 56 |
# File 'lib/rad_settings.rb', line 54 def to_hash Hash[self.instance] end |
Instance Method Details
#to_hash ⇒ Object
60 61 62 |
# File 'lib/rad_settings.rb', line 60 def to_hash Hash[self] end |