Class: HomeQ::Base::Configuration::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
HomeQ::Base::Commando::InstanceMethods, HQ, Singleton
Defined in:
lib/homeq/base/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HomeQ::Base::Commando::InstanceMethods

#add_breakpoint, #config_file, #debug_now, #disable_debugging, #enable_debugging, #log_file, #log_level, #pid_file, #queue, #show_commands, #show_queue, #show_queue_list, #start_profiling, #stop_profiling, #syslog, #topology

Methods included from HomeQ::Base::Commando::ClassMethods

#config_accessor, #document_command

Methods included from CP::Commands

#close, #help, #shutdown

Methods included from HQ

#hq

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



46
47
48
49
# File 'lib/homeq/base/config.rb', line 46

def initialize
  @hash = {}
  @gems = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, args) ⇒ Object

support anything of the form config.foo = bar



55
56
57
58
59
# File 'lib/homeq/base/config.rb', line 55

def method_missing(meth, args)
  if meth.to_s.match(/(.*)=$/)
    @hash[$1] = args
  end
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



44
45
46
# File 'lib/homeq/base/config.rb', line 44

def gems
  @gems
end

Instance Method Details

#configObject



65
66
67
# File 'lib/homeq/base/config.rb', line 65

def config
  self
end

#evaluate_config(lines) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/homeq/base/config.rb', line 69

def evaluate_config(lines)
  # Reload commando methods, as they may have changed.
  self.class.class_eval {
    include Commando::InstanceMethods
  }
  eval(lines)
end

#gem(name, opts = {}) ⇒ Object



61
62
63
# File 'lib/homeq/base/config.rb', line 61

def gem(name, opts = {})
  @gems << [name, opts]
end

#read_config_file(path) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/homeq/base/config.rb', line 77

def read_config_file(path)
  hq.die("Nil config file path") unless path
  File.open(path) { |f|
    begin
      evaluate_config(f.read)
    rescue => e
      e.message << "  Config file: #{path}"
      raise
    end
  }
end