Class: Hackademic::Config
- Inherits:
-
Object
- Object
- Hackademic::Config
- Defined in:
- lib/hackademic/config.rb
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #method_missing(method) ⇒ Object
- #set_config_variable(name, value) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hackademic/config.rb', line 20 def initialize if File.exists?("Resources/Config.yml") raw_config = File.read("Resources/Config.yml") erb_config = ERB.new(raw_config).result settings = YAML.load(erb_config)["hackademic"] if settings settings.each { |name, value| set_config_variable(name, value) } end end def method_missing(method) "" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
32 33 34 |
# File 'lib/hackademic/config.rb', line 32 def method_missing(method) "" end |
Instance Method Details
#set_config_variable(name, value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hackademic/config.rb', line 9 def set_config_variable(name, value) if value.is_a? Hash value.each do |key, value| set_config_variable("#{name}_#{key}", value) end end # puts "=== Setting #{name} to #{value}" instance_variable_set("@#{name}", ENV[name.upcase] || value) self.class.class_eval { attr_reader name.intern } end |