Module: Crystal::Callbacks

Defined in:
lib/crystal/support/callbacks.rb

Defined Under Namespace

Modules: ClassMethods Classes: AbstractCallback, AfterCallback, AroundCallback, BeforeCallback

Instance Method Summary collapse

Instance Method Details

#run_callbacks(callback_name, additional_information = {}, &block) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/crystal/support/callbacks.rb', line 109

def run_callbacks callback_name, additional_information = {}, &block
  callback_name = callback_name.to_s
  block.must_be.defined

  callbacks = self.class.callbacks[callback_name]
  chain_head = block
  if callbacks and !callbacks.empty?
    callbacks.reverse_each do |callback|
      block = callback.add_to_chain self, additional_information, &chain_head
      chain_head = block if block
    end
  end
  chain_head.call
end