Module: Stealth::Controller::Callbacks::ClassMethods

Defined in:
lib/stealth/controller/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#_insert_callbacks(callbacks, block = nil) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/stealth/controller/callbacks.rb', line 30

def _insert_callbacks(callbacks, block = nil)
  options = callbacks.extract_options!
  _normalize_callback_options(options)
  callbacks.push(block) if block
  callbacks.each do |callback|
    yield callback, options
  end
end

#_normalize_callback_option(options, from, to) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/stealth/controller/callbacks.rb', line 22

def _normalize_callback_option(options, from, to)
  if from = options[from]
    _from = Array(from).map(&:to_s).to_set
    from = proc { |c| _from.include?(c.action_name) }
    options[to] = Array(options[to]).unshift(from)
  end
end

#_normalize_callback_options(options) ⇒ Object



17
18
19
20
# File 'lib/stealth/controller/callbacks.rb', line 17

def _normalize_callback_options(options)
  _normalize_callback_option(options, :only, :if)
  _normalize_callback_option(options, :except, :unless)
end