Class: BotMob::Application
- Inherits:
-
Object
- Object
- BotMob::Application
- Defined in:
- lib/bot_mob/application.rb
Overview
## BotMob::Application
This is the base class for BotMob.
Instance Attribute Summary collapse
-
#bot_class ⇒ Object
readonly
Returns the value of attribute bot_class.
-
#bots ⇒ Object
readonly
Returns the value of attribute bots.
Instance Method Summary collapse
- #add_bot(user_id) ⇒ Object
-
#initialize(bot_class) ⇒ Application
constructor
A new instance of Application.
- #register(install) ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize(bot_class) ⇒ Application
Returns a new instance of Application.
8 9 10 11 12 13 |
# File 'lib/bot_mob/application.rb', line 8 def initialize(bot_class) @bot_class = bot_class @bots = {} Install.all.each { |install| register(install) } end |
Instance Attribute Details
#bot_class ⇒ Object (readonly)
Returns the value of attribute bot_class.
6 7 8 |
# File 'lib/bot_mob/application.rb', line 6 def bot_class @bot_class end |
#bots ⇒ Object (readonly)
Returns the value of attribute bots.
6 7 8 |
# File 'lib/bot_mob/application.rb', line 6 def bots @bots end |
Instance Method Details
#add_bot(user_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bot_mob/application.rb', line 21 def add_bot(user_id) BotMob.logger.info "Adding bot: #{user_id}" install = Install.find_by_user_id(user_id) if install.nil? BotMob.logger.info "Could not find bot: #{user_id}" return end register install end |
#register(install) ⇒ Object
32 33 34 35 36 |
# File 'lib/bot_mob/application.rb', line 32 def register(install) bot = bot_class.new(install.user_id, install.token) @bots[install.user_id] ||= bot @bots[install.user_id].refresh end |