Module: Pakyow::Support::Hookable::ClassMethods
- Defined in:
- lib/pakyow/support/hookable.rb
Overview
Class-level api methods.
Instance Attribute Summary collapse
-
#__hook_pipeline ⇒ Object
readonly
Returns the value of attribute __hook_pipeline.
Class Method Summary collapse
Instance Method Summary collapse
-
#after(event, name = nil, priority: , exec: true, &block) ⇒ Object
Defines a hook to call after event occurs.
-
#around(event, name = nil, priority: , exec: true, &block) ⇒ Object
Defines a hook to call before and after event occurs.
-
#before(event, name = nil, priority: , exec: true, &block) ⇒ Object
(also: #on)
Defines a hook to call before event occurs.
-
#events(*events) ⇒ Object
Sets the known events for the hookable object.
- #known_event?(event) ⇒ Boolean private
- #known_hook?(event) ⇒ Boolean
Instance Attribute Details
#__hook_pipeline ⇒ Object (readonly)
Returns the value of attribute __hook_pipeline.
70 71 72 |
# File 'lib/pakyow/support/hookable.rb', line 70 def __hook_pipeline @__hook_pipeline end |
Class Method Details
.extended(base) ⇒ Object
72 73 74 |
# File 'lib/pakyow/support/hookable.rb', line 72 def self.extended(base) base.extend(CommonMethods) end |
Instance Method Details
#after(event, name = nil, priority: , exec: true, &block) ⇒ Object
Defines a hook to call after event occurs.
102 103 104 |
# File 'lib/pakyow/support/hookable.rb', line 102 def after(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) add_hook(:after, event, name, priority, exec, block) end |
#around(event, name = nil, priority: , exec: true, &block) ⇒ Object
Defines a hook to call before and after event occurs.
110 111 112 113 |
# File 'lib/pakyow/support/hookable.rb', line 110 def around(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) add_hook(:before, event, name, priority, exec, block) add_hook(:after, event, name, priority, exec, block) end |
#before(event, name = nil, priority: , exec: true, &block) ⇒ Object Also known as: on
Defines a hook to call before event occurs.
93 94 95 |
# File 'lib/pakyow/support/hookable.rb', line 93 def before(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) add_hook(:before, event, name, priority, exec, block) end |
#events(*events) ⇒ Object
Sets the known events for the hookable object. Hooks registered for an event that doesn’t exist will raise an ArgumentError.
81 82 83 |
# File 'lib/pakyow/support/hookable.rb', line 81 def events(*events) @__events.concat(events.map(&:to_sym)).uniq!; @__events end |
#known_event?(event) ⇒ Boolean
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.
116 117 118 |
# File 'lib/pakyow/support/hookable.rb', line 116 def known_event?(event) @__events.include?(event.to_sym) end |
#known_hook?(event) ⇒ Boolean
120 121 122 123 124 |
# File 'lib/pakyow/support/hookable.rb', line 120 def known_hook?(event) @__hooks.any? { |hook| hook[:name] == event.to_sym } end |