Class: Qbot::Application

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/qbot/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



27
28
29
30
31
32
# File 'lib/qbot/app.rb', line 27

def initialize
  @bots    = []
  @threads = []
  @timers  = Timers::Group.new
  @logger  = Logger.new(STDOUT)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



25
26
27
# File 'lib/qbot/app.rb', line 25

def logger
  @logger
end

#timersObject (readonly)

Returns the value of attribute timers.



24
25
26
# File 'lib/qbot/app.rb', line 24

def timers
  @timers
end

Instance Method Details

#adapterObject



57
58
59
# File 'lib/qbot/app.rb', line 57

def adapter
  @adapter ||= Qbot::Adapter::Driver.build
end

#add(bot) ⇒ Object



34
35
36
# File 'lib/qbot/app.rb', line 34

def add(bot)
  @bots << bot
end

#botsObject



38
39
40
# File 'lib/qbot/app.rb', line 38

def bots
  @bots.map { |bot| bot.class.name }.uniq
end

#startObject



42
43
44
45
46
47
48
49
50
# File 'lib/qbot/app.rb', line 42

def start
  @logger.info("Booting #{self.class}.")
  @logger.info("#{storage.class} - Storage driver loaded")
  @logger.info("#{adapter.class} - Adapter driver loaded")

  @threads << Thread.start { loop { @timers.wait } }
  @threads << Thread.start { adapter.run(@bots) }
  @threads.each { |th| th.join }
end

#stopObject



52
53
54
55
# File 'lib/qbot/app.rb', line 52

def stop
  adapter.stop if adapter.respond_to?(:stop)
  @threads.each { |th| th.kill if th }
end

#storageObject



61
62
63
# File 'lib/qbot/app.rb', line 61

def storage
  @storage ||= Qbot::Storage::Driver.build
end