Module: Resourceful::Default::Callbacks
- Included in:
- Base
- Defined in:
- lib/resourceful/default/callbacks.rb
Overview
This module is mostly meant to be used by the make_resourceful default actions. It provides various methods that declare where callbacks set in the make_resourceful block, like Builder#before and Builder#response_for, should be called.
Instance Method Summary collapse
-
#after(event) ⇒ Object
Calls any
aftercallbacks set in themake_resourcefulblock for the given event. -
#before(event) ⇒ Object
Calls any
beforecallbacks set in themake_resourcefulblock for the given event. -
#response_for(event) ⇒ Object
Calls any
response_forcallbacks set in themake_resourcefulblock for the given event. -
#scope(block) ⇒ Object
Returns a block identical to the given block, but in the context of the current controller.
Instance Method Details
#after(event) ⇒ Object
Calls any after callbacks set in the make_resourceful block for the given event.
16 17 18 |
# File 'lib/resourceful/default/callbacks.rb', line 16 def after(event) resourceful_fire(:after, event.to_sym) end |
#before(event) ⇒ Object
Calls any before callbacks set in the make_resourceful block for the given event.
11 12 13 |
# File 'lib/resourceful/default/callbacks.rb', line 11 def before(event) resourceful_fire(:before, event.to_sym) end |
#response_for(event) ⇒ Object
Calls any response_for callbacks set in the make_resourceful block for the given event. Note that these aren’t called directly, but instead passed along to Rails’ respond_to method.
23 24 25 26 27 28 29 30 31 |
# File 'lib/resourceful/default/callbacks.rb', line 23 def response_for(event) if responses = self.class.resourceful_responses[event.to_sym] respond_to do |format| responses.each do |key, value| format.send(key, &scope(value)) end end end end |
#scope(block) ⇒ Object
Returns a block identical to the given block, but in the context of the current controller. The returned block accepts no arguments, even if the given block accepted them.
37 38 39 40 41 |
# File 'lib/resourceful/default/callbacks.rb', line 37 def scope(block) proc do instance_eval(&(block || proc {})) end end |