Class: CampfireChat::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/campfire_chat/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Configuration

Returns a new instance of Configuration.



18
19
20
21
22
23
# File 'lib/campfire_chat/configuration.rb', line 18

def initialize(attrs={})
  @token = attrs[:token]
  @subdomain = attrs[:subdomain]
  @room = attrs[:room]
  @pairs = []
end

Instance Attribute Details

#pairsObject (readonly)

Returns the value of attribute pairs.



4
5
6
# File 'lib/campfire_chat/configuration.rb', line 4

def pairs
  @pairs
end

#roomObject (readonly)

Returns the value of attribute room.



4
5
6
# File 'lib/campfire_chat/configuration.rb', line 4

def room
  @room
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



4
5
6
# File 'lib/campfire_chat/configuration.rb', line 4

def subdomain
  @subdomain
end

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/campfire_chat/configuration.rb', line 4

def token
  @token
end

Class Method Details

.build(path = nil) ⇒ Object



6
7
8
9
# File 'lib/campfire_chat/configuration.rb', line 6

def self.build(path = nil)
  path ||= Pathname.new(ENV['HOME']).join('.campfire.yml')
  new load_config(path)
end

.load_config(path) ⇒ Object



11
12
13
14
15
16
# File 'lib/campfire_chat/configuration.rb', line 11

def self.load_config(path)
  conf = YAML.load_file(path) || {}
  Hash[conf.map{ |k, v| [k.to_sym, v] }]
rescue Errno::ENOENT, TypeError
  {}
end

Instance Method Details

#add_pair(name) ⇒ Object



25
26
27
# File 'lib/campfire_chat/configuration.rb', line 25

def add_pair(name)
  pairs << CampfireChat::Engineer.new(:name => name)
end