Module: TriggerSwitchD::ConfigFactory

Defined in:
lib/trigger_switch_d/config.rb

Constant Summary collapse

ENV_PATH =
"config/environment.rb"

Class Method Summary collapse

Class Method Details

.new(file = StringIO.new) ⇒ Object

Creates the Config class from the config/config.rb file See samples/config.rb for more documentation



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/trigger_switch_d/config.rb', line 24

def self.new(file=StringIO.new)
  env = file.readlines
  attributes = env.map do |attribute|
    attribute.scan(/Config.([\w_]+) =/).flatten[0]
  end
  attributes.compact!
  cls = <<-EOS
  class Config
     #{attributes.map {|name| "def self.#{name}=(value); #{append_filenames(name)}; end"}.join("\n")}
     
     #{attributes.map {|name| "def self.#{name}; @#{name}; end"}.join("\n")}
     
     def self.default_environment
       {:lookup => {"tänd" => "activate", 
                 "släck" => "deactivate", 
                 "soluppgång" => "sunrise", 
                 "solnedgång" => "sunset",
                 "klockan" => "at",
                 "vid" => "at"},
       :at_location => {:north => 0.0, :west => 0.0}}
     end
  end
  EOS
  ::TriggerSwitchD.module_eval(cls)
  setup_environment(env)
end