Module: Exposure::Callbacks::ClassMethods
- Defined in:
- lib/exposure/behaviors/callbacks.rb
Instance Method Summary collapse
-
#after(trigger, *actions) ⇒ Object
access point for creating and configuring after_ callbacks.
-
#before(trigger, *actions) ⇒ Object
access point for creating and configuring before_ callbacks.
-
#build_callback(prefix, trigger, action, options) ⇒ Object
builds callbacks that adhere to the ActiveSupport::Callbacks interface.
Instance Method Details
#after(trigger, *actions) ⇒ Object
access point for creating and configuring after_ callbacks.
18 19 20 21 22 23 |
# File 'lib/exposure/behaviors/callbacks.rb', line 18 def after(trigger, *actions) = actions. actions.each do |action| build_callback('after', trigger, action, ) end end |
#before(trigger, *actions) ⇒ Object
access point for creating and configuring before_ callbacks.
10 11 12 13 14 15 |
# File 'lib/exposure/behaviors/callbacks.rb', line 10 def before(trigger, *actions) = actions. actions.each do |action| build_callback('before', trigger, action, ) end end |
#build_callback(prefix, trigger, action, options) ⇒ Object
builds callbacks that adhere to the ActiveSupport::Callbacks interface
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/exposure/behaviors/callbacks.rb', line 26 def build_callback(prefix, trigger, action, ) #:nodoc: callback_name = "#{prefix}_#{trigger}" if [:on] callback_name += "_on_#{.delete(:on)}" end [:if] ||= [] only_methods = Array.wrap(.delete(:only)) except_methods = Array.wrap(.delete(:except)) if only_methods.any? [:if] << proc {|c| only_methods.include?(c.action_name.intern) } end if except_methods.any? [:if] << proc {|c| !except_methods.include?(c.action_name.intern) } end self.send(callback_name, action, ) end |