Module: Ray::DSL::EventListener
- Included in:
- Helper
- Defined in:
- lib/ray/dsl/event_listener.rb
Overview
The module that allows you to do something when something else happened.
Instance Method Summary collapse
-
#add_hook(event, ..., callable) ⇒ Object
Same as #on, but the last argument is an object which responds to #to_proc.
- #current_event_group ⇒ Object
- #current_event_group=(val) ⇒ Object
-
#event_group(name) { ... } ⇒ Object
Sets the current event group temporarily.
-
#listener_runner ⇒ Ray::DSL::EventRunner
Object where matchers will be registred.
-
#listener_runner=(arg) ⇒ Object
Sets the event runner which will be used for listening.
-
#on(event, *args, &block) ⇒ Object
Registers a block to listen to an event.
Instance Method Details
#add_hook(event, ..., callable) ⇒ Object
24 25 26 27 28 |
# File 'lib/ray/dsl/event_listener.rb', line 24 def add_hook(event, *args) raise NoRunnerError, self unless listener_runner listener_runner.add_handler(event, current_event_group, args[0...-1], args.last) end |
#current_event_group ⇒ Object
45 46 47 |
# File 'lib/ray/dsl/event_listener.rb', line 45 def current_event_group @__listener_event_group ||= :default end |
#current_event_group=(val) ⇒ Object
49 50 51 |
# File 'lib/ray/dsl/event_listener.rb', line 49 def current_event_group=(val) @__listener_event_group = val end |
#event_group(name) { ... } ⇒ Object
Sets the current event group temporarily.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ray/dsl/event_listener.rb', line 34 def event_group(name) old_group = current_event_group self.current_event_group = name begin yield name ensure self.current_event_group = old_group end end |
#listener_runner ⇒ Ray::DSL::EventRunner
Returns Object where matchers will be registred.
54 55 56 |
# File 'lib/ray/dsl/event_listener.rb', line 54 def listener_runner @__listener_runner if defined?(@__listener_runner) end |
#listener_runner=(arg) ⇒ Object
Sets the event runner which will be used for listening.
60 61 62 |
# File 'lib/ray/dsl/event_listener.rb', line 60 def listener_runner=(arg) @__listener_runner = arg end |
#on(event, *args, &block) ⇒ Object
Registers a block to listen to an event.
Arguments are compared with the ones of the regex using === and, if it failed, ==.
13 14 15 16 |
# File 'lib/ray/dsl/event_listener.rb', line 13 def on(event, *args, &block) raise NoRunnerError, self unless listener_runner listener_runner.add_handler(event, current_event_group, args, block) end |