Module: SlackRubyBot::Hooks::HookSupport

Included in:
Server
Defined in:
lib/slack-ruby-bot/hooks/hook_support.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 6

def self.included(base)
  base.cattr_accessor :hook_blocks

  base.extend(ClassMethods)
end

Instance Method Details

#add_hook_handlers(handler_hash) ⇒ Object

TODO: This should be deprecated in favor of ‘on`



32
33
34
35
36
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 32

def add_hook_handlers(handler_hash)
  handler_hash.each do |hook, handlers|
    Array(handlers).each { |handler| on(hook, handler) }
  end
end

#flush_hook_blocksObject



25
26
27
28
29
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 25

def flush_hook_blocks
  return nil unless self.class.hook_blocks

  add_hook_handlers(self.class.hook_blocks)
end

#on(event_name, handler) ⇒ Object



21
22
23
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 21

def on(event_name, handler)
  _hooks.add(event_name, handler)
end