class SlackRubyBot::Hooks::Set
Attributes
client[RW]
handlers[RW]
Public Class Methods
new(client = nil)
click to toggle source
# File lib/slack-ruby-bot/hooks/set.rb, line 8 def initialize(client = nil) self.handlers = {} self.client = client @pending_flush = client.blank? end
Public Instance Methods
add(hook_name, handler)
click to toggle source
# File lib/slack-ruby-bot/hooks/set.rb, line 15 def add(hook_name, handler) handlers[hook_name] ||= ::Set.new handlers[hook_name] << handler register_callback(hook_name) end
client=(client)
click to toggle source
# File lib/slack-ruby-bot/hooks/set.rb, line 22 def client=(client) @client = client flush_handlers if @pending_flush end
Protected Instance Methods
flush_handlers()
click to toggle source
# File lib/slack-ruby-bot/hooks/set.rb, line 40 def flush_handlers handlers.each_key { |hook| register_callback(hook) } end
register_callback(hook_name)
click to toggle source
# File lib/slack-ruby-bot/hooks/set.rb, line 30 def register_callback(hook_name) return unless client # We'll delay this until client is set client.on hook_name do |data| handlers[hook_name].each do |handler| handler.call(client, data) end end end