Method: Beeta::Config.load

Defined in:
lib/beeta/config.rb

.load(fn = nil, force = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/beeta/config.rb', line 14

def self.load(fn = nil, force = false)
  fn ||= ConfigFile
  return false if(fn.nil? || (!force && loaded))

  self.config = JSON.parse File.read(fn)
  # TODO:  When the config solidifies reasonably, get rid of the
  # overly metaprogrammed bits here, and replace with regular
  # methods.  It's just a little easier for now to be able to add
  # values to the config file and have the methods appear out of
  # nowhere.
  config.each { |k,v|
    class << self; self; end.module_eval {
      define_method(k) { v }
    }
  }

  self.loaded = true
end