Class: CeilingCat::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/ceiling_cat/setup.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_config = nil) ⇒ Setup

Returns a new instance of Setup.



31
32
33
# File 'lib/ceiling_cat/setup.rb', line 31

def initialize(_config = nil)
  self.config = _config || self.class.config
end

Class Attribute Details

.configObject

Class-level config. This is set by the configure class method, and is used if no configuration is passed to the initialize method.



12
13
14
# File 'lib/ceiling_cat/setup.rb', line 12

def config
  @config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/ceiling_cat/setup.rb', line 6

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Configures the connection at the class level. When the ceiling_cat bin file is loaded, it evals the file referenced by the first command-line parameter. This file can configure the connection instance later created by robut by setting parameters in the CeilingCat::Connection.configure block.

Yields:



20
21
22
23
# File 'lib/ceiling_cat/setup.rb', line 20

def self.configure
  self.config = OpenStruct.new
  yield config
end

Instance Method Details

#connectObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ceiling_cat/setup.rb', line 35

def connect
  case self.config.service.downcase
  when 'campfire'
    connection = CeilingCat::Campfire::Connection.new(self.config)
    room = CeilingCat::Campfire::Room.new(:connection => connection, :room_name => self.config.room)
    room.watch
  when 'irc'
    connection = CeilingCat::IRC::Connection.new(self.config)
    room = CeilingCat::IRC::Room.new(:connection => connection, :room_name => self.config.room)
    room.watch
  else
    raise CeilingCat::UnsupportedChatServiceError.new("#{self.config.service} is not a supported chat service.")
  end
end