Class: JabberTee::ConfigurationReader

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber-tee/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(yaml_file) ⇒ ConfigurationReader

Returns a new instance of ConfigurationReader.



10
11
12
13
14
15
16
17
18
# File 'lib/jabber-tee/configuration.rb', line 10

def initialize(yaml_file)
  if !File.exists?(yaml_file)
    raise JabberTee::ConfigurationError.new("Unable to locate the configuration file.")
  end

  yaml = nil
  file = File.open(yaml_file) {|f| yaml = f.read }
  @config = YAML::load(yaml)
end

Instance Method Details

#profile(name = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jabber-tee/configuration.rb', line 20

def profile(name=nil)
  if name.nil?
    Configuration.new(@config)
  else
    config = Configuration.new(@config)
    profiles = @config['profiles']
    if profiles.nil?
      raise JabberTee::ConfigurationError.new("Unable to load an profiles from your home configuration.")
    end
    profile = profiles[name]
    if config.nil?
      raise JabberTee::ConfigurationError.new("Unable to load the #{name} profile from your home configuration.")
    end
    config.merge(profile)
  end
end