Module: Boty::Eventable

Includes:
Logger
Included in:
Bot
Defined in:
lib/boty/eventable.rb

Instance Attribute Summary

Attributes included from Logger

#logger

Instance Method Summary collapse

Methods included from Logger

adapter, adapter=, #log_error

Instance Method Details

#event(data) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/boty/eventable.rb', line 9

def event(data)
  type = event_type data
  return unless type

  events[type].each do |action|
    action.call data
  end
end

#eventsObject



5
6
7
# File 'lib/boty/eventable.rb', line 5

def events
  @events ||= {}
end

#off(event_type, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/boty/eventable.rb', line 23

def off(event_type, &block)
  if block_given?
    events[event_type].delete_if { |b| b == block }
  else
    events[event_type] = []
  end
end

#on(event_type, &block) ⇒ Object



18
19
20
21
# File 'lib/boty/eventable.rb', line 18

def on(event_type, &block)
  events[event_type.to_sym] ||= []
  events[event_type.to_sym] << block
end