Class: Qbot::Application
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Instance Method Summary collapse
- #adapter ⇒ Object
- #add(bot) ⇒ Object
- #bots ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #start ⇒ Object
- #stop ⇒ Object
- #storage ⇒ Object
Constructor Details
#initialize ⇒ Application
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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
25 26 27 |
# File 'lib/qbot/app.rb', line 25 def logger @logger end |
#timers ⇒ Object (readonly)
Returns the value of attribute timers.
24 25 26 |
# File 'lib/qbot/app.rb', line 24 def timers @timers end |
Instance Method Details
#adapter ⇒ Object
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 |
#bots ⇒ Object
38 39 40 |
# File 'lib/qbot/app.rb', line 38 def bots @bots.map { |bot| bot.class.name }.uniq end |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |
#storage ⇒ Object
61 62 63 |
# File 'lib/qbot/app.rb', line 61 def storage @storage ||= Qbot::Storage::Driver.build end |