Module: Nova::Common::EventHandler::ClassMethods
- Included in:
- InstanceMethods, Star
- Defined in:
- lib/nova/common/event_handler.rb
Overview
Class methods.
Instance Method Summary collapse
-
#events ⇒ Set<EventHandler::Event>
A list of all of the events defined in the class.
-
#has_event?(name) ⇒ nil, Event
Checks to see if an event with the given name exists.
-
#has_event_with_options?(name, options = {}) ⇒ nil, Event
Checks to see if an event can respond to the given name and options.
-
#on(event, options = {}) {|options| ... } ⇒ Event
(also: #to)
Creates an event, adds it to the list, and returns it.
Instance Method Details
#events ⇒ Set<EventHandler::Event>
A list of all of the events defined in the class.
16 17 18 |
# File 'lib/nova/common/event_handler.rb', line 16 def events @_events ||= Set.new end |
#has_event?(name) ⇒ nil, Event
Note:
Even if the event with the given name may exist, the event may still not exist if the options don’t match. If you want to make sure that the event will respond to the name and options, check #has_event_with_options?.
Checks to see if an event with the given name exists.
44 45 46 |
# File 'lib/nova/common/event_handler.rb', line 44 def has_event?(name) events.dup.keep_if { |e| e.name == name }.to_a.first end |
#has_event_with_options?(name, options = {}) ⇒ nil, Event
Checks to see if an event can respond to the given name and options.
54 55 56 57 58 |
# File 'lib/nova/common/event_handler.rb', line 54 def (name, = {}) event = Event.new(name, ) event.type = :search events.dup.keep_if { |e| e.match? Star.new, event }.to_a.first end |
#on(event, options = {}) {|options| ... } ⇒ Event Also known as: to
Creates an event, adds it to the list, and returns it.
30 31 32 |
# File 'lib/nova/common/event_handler.rb', line 30 def on(event, = {}) events << Event.new(event, , Proc.new) end |