Class: Hanami::Utils::Callbacks::Chain
- Defined in:
- gems/gems/hanami-utils-2.2.0.beta1/lib/hanami/utils/callbacks.rb
Overview
Series of callbacks to be executed
Instance Attribute Summary collapse
- #chain ⇒ Object readonly protected
Instance Method Summary collapse
-
#append(*callbacks, &block) ⇒ void
Appends the given callbacks to the end of the chain.
-
#dup ⇒ Hanami::Utils::Callbacks
Return a duplicate callbacks 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 = Concurrent::Array.new end |
Instance Attribute Details
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 |
#dup ⇒ Hanami::Utils::Callbacks
Return a duplicate callbacks chain
Source: | on GitHub
def dup super.tap do |instance| instance.instance_variable_set(:@chain, instance.chain.dup) end 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 |