Module: EXEL::Events

Included in:
ListenInstruction
Defined in:
lib/exel/events.rb

Overview

Provides methods for registering and triggering event listeners

Constant Summary collapse

LISTENERS_KEY =
:_listeners

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



16
17
18
# File 'lib/exel/events.rb', line 16

def self.included(other)
  other.class_eval { attr_reader :context }
end

Instance Method Details

#register_listener(context, event, listener) ⇒ Object



8
9
10
# File 'lib/exel/events.rb', line 8

def register_listener(context, event, listener)
  listeners_for_event(event, context) << listener
end

#trigger(event, data = {}) ⇒ Object



12
13
14
# File 'lib/exel/events.rb', line 12

def trigger(event, data = {})
  listeners_for_event(event, context).each { |listener| listener.send(event, context, data) }
end