Sha256: c0739af3be3a9619f8954e7ce517ab5d9452d148e717cdf3840a8bc8ece96b4e
Contents?: true
Size: 969 Bytes
Versions: 8
Compression:
Stored size: 969 Bytes
Contents
module SlackRubyBot module Hooks class Set attr_accessor :handlers, :client def initialize(client = nil) self.handlers = {} self.client = client @pending_flush = client.blank? end def add(hook_name, handler) if handlers[hook_name].present? handlers[hook_name] << handler else handlers[hook_name] = [handler] register_callback(hook_name) end end def client=(client) @client = client flush_handlers if @pending_flush end protected 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 def flush_handlers handlers.keys.each { |hook| register_callback(hook) } end end end end
Version data entries
8 entries across 8 versions & 1 rubygems