Class: Vines::Agent::Config
- Inherits:
-
Object
- Object
- Vines::Agent::Config
- Defined in:
- lib/vines/agent/config.rb
Overview
A Config object is passed to the xmpp connections to give them access to configuration information like server host names, passwords, etc. This class provides the DSL methods used in the conf/config.rb file.
Defined Under Namespace
Classes: Domain
Constant Summary collapse
- LOG_LEVELS =
%w[debug info warn error fatal].freeze
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #domain(name = nil, &block) ⇒ Object
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
- #log(level) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
21 22 23 24 25 |
# File 'lib/vines/agent/config.rb', line 21 def initialize(&block) @domain = nil instance_eval(&block) raise "must define a domain" unless @domain end |
Class Method Details
.configure(&block) ⇒ Object
13 14 15 |
# File 'lib/vines/agent/config.rb', line 13 def self.configure(&block) @@instance = self.new(&block) end |
.instance ⇒ Object
17 18 19 |
# File 'lib/vines/agent/config.rb', line 17 def self.instance @@instance end |
Instance Method Details
#domain(name = nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/vines/agent/config.rb', line 37 def domain(name=nil, &block) if name raise 'multiple domains not allowed' if @domain @domain = Domain.new(name, &block) else @domain end end |
#log(level) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/vines/agent/config.rb', line 27 def log(level) const = Logger.const_get(level.to_s.upcase) rescue nil unless LOG_LEVELS.include?(level.to_s) && const raise "log level must be one of: #{LOG_LEVELS.join(', ')}" end log = Class.new.extend(Vines::Log).log log.progname = 'vines-agent' log.level = const end |
#start ⇒ Object
46 47 48 |
# File 'lib/vines/agent/config.rb', line 46 def start @domain.start end |