Sha256: 94822dd3b4de1561d6cae9823bd0a50a95b399828fe95845c57cd8a6f0016921
Contents?: true
Size: 954 Bytes
Versions: 2
Compression:
Stored size: 954 Bytes
Contents
require 'yaml' unless defined?(YAML) require 'ostruct' require 'singleton' class AppBox < OpenStruct include Singleton 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 def self.method_missing(name, *args, &block) AppBox.instance.send(name, *args) end def self.set_property(name, value, parent=AppBox) if value.class == String 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
app_box-0.2.4 | lib/app_box.rb |
app_box-0.2.2 | lib/app_box.rb |