Module: Rackr::Action::Callbacks::ClassMethods

Defined in:
lib/rackr/action/callbacks.rb

Overview

Class methods for callbacks

Instance Method Summary collapse

Instance Method Details

#after(callback) ⇒ Object



34
35
36
37
# File 'lib/rackr/action/callbacks.rb', line 34

def after(callback)
  @afters ||= []
  @afters.concat(ensure_array(callback))
end

#aftersObject



39
40
41
# File 'lib/rackr/action/callbacks.rb', line 39

def afters
  @afters || []
end

#before(callback) ⇒ Object



25
26
27
28
# File 'lib/rackr/action/callbacks.rb', line 25

def before(callback)
  @befores ||= []
  @befores.concat(ensure_array(callback))
end

#beforesObject



30
31
32
# File 'lib/rackr/action/callbacks.rb', line 30

def befores
  @befores || []
end

#inherited(subclass) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rackr/action/callbacks.rb', line 16

def inherited(subclass)
  super
  # When a class inherits, it should get a copy of the parent's callbacks
  # so that its own additions don't modify the parent's list.
  # Using .dup to ensure a new array object is created for the subclass.
  subclass.instance_variable_set(:@befores, befores.dup) if instance_variable_defined?(:@befores)
  subclass.instance_variable_set(:@afters, afters.dup) if instance_variable_defined?(:@afters)
end