Class: Evilution::Hooks::Registry Private
- Inherits:
-
Object
- Object
- Evilution::Hooks::Registry
- Defined in:
- lib/evilution/hooks/registry.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #clear(event = nil) ⇒ Object private
- #fire(event, **payload) ⇒ Object private
- #handlers_for(event) ⇒ Object private
-
#initialize(on_error: nil) ⇒ Registry
constructor
private
A new instance of Registry.
- #register(event, &block) ⇒ Object private
Constructor Details
#initialize(on_error: nil) ⇒ Registry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Registry.
6 7 8 9 |
# File 'lib/evilution/hooks/registry.rb', line 6 def initialize(on_error: nil) @handlers = Evilution::Hooks::EVENTS.to_h { |event| [event, []] } @on_error = on_error end |
Instance Method Details
#clear(event = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 40 |
# File 'lib/evilution/hooks/registry.rb', line 33 def clear(event = nil) if event validate_event!(event) @handlers[event].clear else @handlers.each_value(&:clear) end end |
#fire(event, **payload) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/evilution/hooks/registry.rb', line 19 def fire(event, **payload) validate_event!(event) errors = [] @handlers[event].each do |handler| handler.call(payload) rescue StandardError => e errors << e report_error(event, e) end errors end |
#handlers_for(event) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 |
# File 'lib/evilution/hooks/registry.rb', line 42 def handlers_for(event) validate_event!(event) @handlers[event].dup end |
#register(event, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 14 15 16 17 |
# File 'lib/evilution/hooks/registry.rb', line 11 def register(event, &block) validate_event!(event) raise ArgumentError, "a block must be provided when registering handler for #{event}" unless block @handlers[event] << block self end |