Class: Nova::Common::EventHandler::Event
- Inherits:
-
Object
- Object
- Nova::Common::EventHandler::Event
- Includes:
- Comparable
- Defined in:
- lib/nova/common/event_handler/event.rb
Overview
This represents an event that can be run. It may also represent an event that will be run, and is being used to match the events in the set. Basically, an event is defined when :on is called on a Star, and an Event is created. It is added to an event list, which is a set. Later, when that class is instantized, and an event is ran, an Event is created and the set is searched for a match to that Event.
Instance Attribute Summary collapse
-
#block ⇒ Proc
readonly
The block defined for the event.
-
#name ⇒ Symbol
readonly
The name of the event.
-
#options ⇒ Hash
readonly
The options defined at compile time for the event.
-
#type ⇒ Symbol
The type of Event this is.
Instance Method Summary collapse
-
#<=>(other) ⇒ Numeric
Compares this event to another event.
-
#initialize(name, options, block = nil) ⇒ Event
constructor
Initialize the event.
-
#match?(star, event) ⇒ Boolean
Whether or not this event matches another event, to see if it can be ran using this event definition.
-
#run(context, options = {}) ⇒ Object?
Runs the event, calling the block with the given options.
-
#search? ⇒ Boolean
Whether or not this event is a search event.
Constructor Details
#initialize(name, options, block = nil) ⇒ Event
Initialize the event.
60 61 62 63 64 65 |
# File 'lib/nova/common/event_handler/event.rb', line 60 def initialize(name, , block = nil) @name = name @options = @block = block @type = :definition end |
Instance Attribute Details
#block ⇒ Proc (readonly)
The block defined for the event. Should be able to accept one parameter, or less.
31 32 33 |
# File 'lib/nova/common/event_handler/event.rb', line 31 def block @block end |
#name ⇒ Symbol (readonly)
The name of the event.
20 21 22 |
# File 'lib/nova/common/event_handler/event.rb', line 20 def name @name end |
#options ⇒ Hash (readonly)
The options defined at compile time for the event.
25 26 27 |
# File 'lib/nova/common/event_handler/event.rb', line 25 def @options end |
#type ⇒ Symbol
The type of Nova::Common::EventHandler::Event this is. By default, this value is :definition, but when using this event to find another event, its value should be :search.
38 39 40 |
# File 'lib/nova/common/event_handler/event.rb', line 38 def type @type end |
Instance Method Details
#<=>(other) ⇒ Numeric
Compares this event to another event. If the argument isn’t an Nova::Common::EventHandler::Event, it is compared to the name of the event. If it is, the event’s names and options are compared.
73 74 75 76 77 |
# File 'lib/nova/common/event_handler/event.rb', line 73 def <=>(other) return @name == other unless Event === other (@name <=> other.name) + (@options <=> other.) end |
#match?(star, event) ⇒ Boolean
Whether or not this event matches another event, to see if it can be ran using this event definition.
107 108 109 110 |
# File 'lib/nova/common/event_handler/event.rb', line 107 def match?(star, event) event.name == name && check_platform_requirement(star) && (event.) end |
#run(context, options = {}) ⇒ Object?
Runs the event, calling the block with the given options.
84 85 86 87 88 89 90 91 92 |
# File 'lib/nova/common/event_handler/event.rb', line 84 def run(context, = {}) #@block.call(options) if @options[:defaults] = @options[:defaults].merge() end context.instance_exec(, &@block) end |
#search? ⇒ Boolean
Whether or not this event is a search event.
97 98 99 |
# File 'lib/nova/common/event_handler/event.rb', line 97 def search? type == :search end |