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



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

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`



36
37
38
39
40
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 36

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

#flush_hook_blocksObject



29
30
31
32
33
# File 'lib/slack-ruby-bot/hooks/hook_support.rb', line 29

def flush_hook_blocks
  return nil unless self.class.hook_blocks

  add_hook_handlers(self.class.hook_blocks)
end

#hooksObject

Instance stuff



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

def hooks
  warn Kernel.caller.first + ' [DEPRECATION] `hooks` method is deprecated. Please use `server.on` instead to register a hook.'
  _hooks
end

#on(event_name, handler) ⇒ Object



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

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