class BotMob::Roster

## BotMob::Roster

This manages the pool of bots made available by the application

Attributes

bots[R]

Public Class Methods

new() click to toggle source
# File lib/bot_mob/roster.rb, line 9
def initialize
  @bots = []
end

Public Instance Methods

disseminate(action, params = {}) click to toggle source

## `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

# 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) click to toggle source
# File lib/bot_mob/roster.rb, line 13
def register(bot, **options)
  @bots << (bot.is_a?(Class) ? bot.new(options) : bot)
end

Private Instance Methods

handle_command(bot, params) click to toggle source
# File lib/bot_mob/roster.rb, line 35
def handle_command(bot, params)
  method_name = params[:method].to_sym
  bot.receive_command(method_name, params)
end
handle_message(bot, params) click to toggle source
# File lib/bot_mob/roster.rb, line 31
def handle_message(bot, params)
  bot.receive(params)
end