Class: AppBox
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- AppBox
- Includes:
- Singleton
- Defined in:
- lib/app_box.rb
Class Method Summary collapse
- .init(env, rails_root) ⇒ Object
- .method_missing(name, *args, &block) ⇒ Object
- .set_property(name, value, parent = AppBox) ⇒ Object
Class Method Details
.init(env, rails_root) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/app_box.rb', line 8 def self.init(env, rails_root) config_path = "#{rails_root}/config/app_box.yml" if File.exists?(config_path) data = YAML.load_file(config_path) data['default'].each {|name, value| set_property(name, value)} if data.include?(env) data[env].each {|name, value| set_property(name, value)} end end end |
.method_missing(name, *args, &block) ⇒ Object
19 20 21 |
# File 'lib/app_box.rb', line 19 def self.method_missing(name, *args, &block) AppBox.instance.send(name, *args) end |
.set_property(name, value, parent = AppBox) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/app_box.rb', line 23 def self.set_property(name, value, parent=AppBox) if value.class == String || value.class == Array if parent.nil? AppBox.send "#{name}=", value else parent.send "#{name}=", value end elsif value.class == Hash parent = parent.send "#{name}=", OpenStruct.new value.each do |_name, _value| set_property(_name, _value, parent) end end end |