Class: Houston::Extensions::Events
- Inherits:
-
Object
- Object
- Houston::Extensions::Events
- Includes:
- Enumerable
- Defined in:
- lib/houston/boot/extensions/events.rb
Instance Method Summary collapse
- #[](event_name) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Events
constructor
A new instance of Events.
- #register(&block) ⇒ Object
- #registered?(event_name) ⇒ Boolean
Methods included from Enumerable
Constructor Details
#initialize ⇒ Events
Returns a new instance of Events.
8 9 10 |
# File 'lib/houston/boot/extensions/events.rb', line 8 def initialize @events = Concurrent::Array.new end |
Instance Method Details
#[](event_name) ⇒ Object
16 17 18 |
# File 'lib/houston/boot/extensions/events.rb', line 16 def [](event_name) @events.find { |event| event.matches? event_name } end |
#each(&block) ⇒ Object
12 13 14 |
# File 'lib/houston/boot/extensions/events.rb', line 12 def each(&block) @events.each(&block) end |
#register(&block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/houston/boot/extensions/events.rb', line 24 def register(&block) dsl = RegisterEventsDsl.new hash = dsl.instance_eval(&block) hash.each do |name, description| @events.push Event.new(name, description.to_h) end end |
#registered?(event_name) ⇒ Boolean
20 21 22 |
# File 'lib/houston/boot/extensions/events.rb', line 20 def registered?(event_name) @events.any? { |event| event.matches? event_name } end |