Class: BotMob::Roster
- Inherits:
-
Object
- Object
- BotMob::Roster
- Defined in:
- lib/bot_mob/roster.rb
Overview
## BotMob::Roster
This manages the pool of bots made available by the application
Instance Attribute Summary collapse
-
#bots ⇒ Object
readonly
Returns the value of attribute bots.
Instance Method Summary collapse
-
#disseminate(action, params = {}) ⇒ Object
## ‘disseminate`.
-
#initialize ⇒ Roster
constructor
A new instance of Roster.
- #register(bot, **options) ⇒ Object
Constructor Details
#initialize ⇒ Roster
Returns a new instance of Roster.
9 10 11 |
# File 'lib/bot_mob/roster.rb', line 9 def initialize @bots = [] end |
Instance Attribute Details
#bots ⇒ Object (readonly)
Returns the value of attribute bots.
7 8 9 |
# File 'lib/bot_mob/roster.rb', line 7 def bots @bots end |
Instance Method Details
#disseminate(action, params = {}) ⇒ Object
## ‘disseminate`
This method will distribute a message or command to all bots on the roster. It collects and returns a compacted array of the bots’ responses
22 23 24 25 26 27 |
# File 'lib/bot_mob/roster.rb', line 22 def disseminate(action, params = {}) bots.map do |bot| approach = "handle_#{action}".to_sym respond_to?(approach, true) ? send(approach, bot, params) : nil end.compact end |
#register(bot, **options) ⇒ Object
13 14 15 |
# File 'lib/bot_mob/roster.rb', line 13 def register(bot, **) @bots << (bot.is_a?(Class) ? bot.new() : bot) end |