Class: Wildsight::Agent::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/wildsight/agent/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Config

Returns a new instance of Config.



17
18
19
# File 'lib/wildsight/agent/config.rb', line 17

def initialize(values = {})
  @values = values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



21
22
23
24
# File 'lib/wildsight/agent/config.rb', line 21

def method_missing(name, *args)
  name = name.to_s
  self[name]
end

Class Method Details

.load(file = (ENV['WILDSIGHT_CONFIG_FILE'] || 'config/wildsight.yml')) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/wildsight/agent/config.rb', line 8

def self.load(file = (ENV['WILDSIGHT_CONFIG_FILE'] || 'config/wildsight.yml'))
  options = YAML.load(File.read(File.expand_path('../config.yml', __FILE__)))
  options = options.merge(file) if file.kind_of?(Hash)
  if file.kind_of?(String) && File.exist?(file)
    options = options.merge(YAML.load(File.read(file)))
  end
  Config.new(options)
end

Instance Method Details

#[](name) ⇒ Object



26
27
28
29
30
# File 'lib/wildsight/agent/config.rb', line 26

def [](name)
  name = name.to_s
  @values[name] = Config.new(@values[name]) if @values[name].kind_of?(Hash)
  @values[name]
end