Class: Hanami::Utils::Callbacks::Chain
- Inherits:
-
Object
- Object
- Hanami::Utils::Callbacks::Chain
- Defined in:
- gems/gems/hanami-utils-1.3.3/lib/hanami/utils/callbacks.rb,
gems/gems/hanami-utils-1.3.8/lib/hanami/utils/callbacks.rb
Overview
Series of callbacks to be executed
Instance Method Summary collapse
-
#append(*callbacks, &block) ⇒ void
Appends the given callbacks to the end of the chain.
-
#freeze ⇒ Object
It freezes the object by preventing further modifications.
-
#initialize ⇒ Hanami::Utils::Callbacks::Chain
constructor
Returns a new chain.
-
#prepend(*callbacks, &block) ⇒ void
Prepends the given callbacks to the beginning of the chain.
-
#run(context, *args) ⇒ Object
Runs all the callbacks in the chain.
Constructor Details
#initialize ⇒ Hanami::Utils::Callbacks::Chain
Returns a new chain
Source: | on GitHub
def initialize @chain = [] end |
Instance Method Details
#append(*callbacks, &block) ⇒ void
This method returns an undefined value.
Appends the given callbacks to the end of the chain.
Source: | on GitHub
def append(*callbacks, &block) callables(callbacks, block).each do |c| @chain.push(c) end @chain.uniq! end |
#freeze ⇒ Object
It freezes the object by preventing further modifications.
Source: | on GitHub
def freeze super @chain.freeze end |
#prepend(*callbacks, &block) ⇒ void
This method returns an undefined value.
Prepends the given callbacks to the beginning of the chain.
Source: | on GitHub
def prepend(*callbacks, &block) callables(callbacks, block).each do |c| @chain.unshift(c) end @chain.uniq! end |
#run(context, *args) ⇒ Object
Runs all the callbacks in the chain. The only two ways to stop the execution are: raise
or throw
.
Source: | on GitHub
def run(context, *args) @chain.each do |callback| callback.call(context, *args) end end |