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.



7
8
9
10
11
12
13
# File 'lib/jabber-tee/configuration.rb', line 7

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

  @config = YAML::load_file(yaml_file)
end

Instance Method Details

#profile(name = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jabber-tee/configuration.rb', line 15

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 profile.nil?
      raise JabberTee::ConfigurationError.new("Unable to load the '#{name}' profile from your home configuration.")
    end
    config.merge(profile)
  end
end