Module: Nova::Common::EventHandler::InstanceMethods
Overview
Instance methods.
Instance Method Summary collapse
- #bind(bind = nil) ⇒ Object
-
#bind!(bind) ⇒ self
Binds this event handler to a given object, running all events in the context of that object.
-
#events ⇒ Set<EventHandler::Event>
Returns the event list.
-
#has_event_with_options?(name, options = {}) ⇒ nil, Event
Checks to see if an event can respond to the given name and options.
-
#initialize ⇒ Object
Automatically binds the Star to itself on initialization.
-
#run(name, options = {}) ⇒ Object, NoEventError
Calls #run!, but if it raises a [NoEventError] it returns it instead of raising it.
-
#run!(name, options = {}) ⇒ Object
Runs an event, with the given name and options.
Methods included from ClassMethods
Instance Method Details
#bind(bind) ⇒ Feature #bind ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/nova/common/event_handler.rb', line 145 def bind(bind = nil) if bind dup.bind!(bind) else @bind ||= Object.new end end |
#bind!(bind) ⇒ self
Binds this event handler to a given object, running all events in the context of that object.
129 130 131 132 |
# File 'lib/nova/common/event_handler.rb', line 129 def bind!(bind) @bind = bind self end |
#events ⇒ Set<EventHandler::Event>
Returns the event list.
76 77 78 |
# File 'lib/nova/common/event_handler.rb', line 76 def events @_events ||= self.class.events.dup end |
#has_event_with_options?(name, options = {}) ⇒ nil, Event
Checks to see if an event can respond to the given name and options.
85 86 87 88 89 |
# File 'lib/nova/common/event_handler.rb', line 85 def (name, = {}) event = Event.new(name, ) event.type = :search events.dup.keep_if { |e| e.match? self, event }.to_a.first end |
#initialize ⇒ Object
Automatically binds the Star to itself on initialization.
67 68 69 70 |
# File 'lib/nova/common/event_handler.rb', line 67 def initialize(*) bind remote.new super() end |
#run(name, options = {}) ⇒ Object, NoEventError
Calls #run!, but if it raises a [NoEventError] it returns it instead of raising it.
exception.
116 117 118 119 120 121 |
# File 'lib/nova/common/event_handler.rb', line 116 def run(name, = {}) run! name, rescue NoEventError => e e end |
#run!(name, options = {}) ⇒ Object
Runs an event, with the given name and options.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/nova/common/event_handler.rb', line 98 def run!(name, = {}) matched = name, = Metadata::Options.new() if matched matched.run(bind, ) else raise NoEventError, "Could not find event #{name}." end end |