module Nova::Common::EventHandler::ClassMethods

Class methods.

Public Instance Methods

events() click to toggle source

A list of all of the events defined in the class.

@return [Set<EventHandler::Event>]

# File lib/nova/common/event_handler.rb, line 16
def events
  @_events ||= Set.new
end
has_event?(name) click to toggle source

Checks to see if an event with the given name exists.

@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?}.

@param name [Symbol] the name of the event. @return [nil, Event]

# 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 = {}) click to toggle source

Checks to see if an event can respond to the given name and options.

@param name [Symbol] the name of the event. @param options [Hash] the options for the event. @return [nil, Event]

# File lib/nova/common/event_handler.rb, line 54
def has_event_with_options?(name, options = {})
  event = Event.new(name, options)
  event.type = :search
  events.dup.keep_if { |e| e.match? Star.new, event }.to_a.first
end
on(event, options = {}) click to toggle source

Creates an event, adds it to the list, and returns it.

@param event [Symbol] the name of the event. @param options [Hash] the options for the event, when creating

it.

@yieldparam options [Hash] the options for the event when ran.

The contents of the options hash is defined at the time when
ran.

@option (see Event#initialize) @return [Event] the event.

# File lib/nova/common/event_handler.rb, line 30
def on(event, options = {})
  events << Event.new(event, options, Proc.new)
end
Also aliased as: to
to(event, options = {})
Alias for: on