Class: Callback::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/action_callback/callback.rb

Overview

The chain should have each method that has callback as key and each callback points to a hash with :before, :after as key each of those keys points to an array of callbacks {

method: {
  before: [...],
  after:  [...]
}

}

Constant Summary collapse

CALLBACK_HOOK =
[:before, :after].freeze

Instance Method Summary collapse

Constructor Details

#initializeChain

Returns a new instance of Chain.



16
17
18
19
20
# File 'lib/action_callback/callback.rb', line 16

def initialize
  CALLBACK_HOOK.each do |cb_hook|
    instance_variable_set("@_#{cb_hook}_chain", new_chain)
  end
end

Instance Method Details

#append_callback(callback_hook, mth, callback) ⇒ Object



22
23
24
25
# File 'lib/action_callback/callback.rb', line 22

def append_callback(callback_hook, mth, callback)
  chain = get_chain(callback_hook)
  chain[mth] << callback
end