| Module | ResourceController::Helpers::Internal |
| In: |
../lib/resource_controller/helpers/internal.rb
|
# File ../lib/resource_controller/helpers/internal.rb, line 70
70: def invoke_callbacks(*callbacks)
71: unless callbacks.empty?
72: callbacks.select { |callback| callback.is_a? Symbol }.each { |symbol| send(symbol) }
73:
74: block = callbacks.detect { |callback| callback.is_a? Proc }
75: instance_eval &block unless block.nil?
76: end
77: end
Returns the options for an action, which is a symbol.
Manages splitting things like :create_fails.
# File ../lib/resource_controller/helpers/internal.rb, line 62
62: def options_for(action)
63: action = action == :new_action ? [action] : "#{action}".split('_').map(&:to_sym)
64: options = self.class.send(action.first)
65: options = options.send(action.last == :fails ? :fails : :success) if ResourceController::FAILABLE_ACTIONS.include? action.first
66:
67: options
68: end
Used to actually pass the responses along to the controller‘s respond_to method.
# File ../lib/resource_controller/helpers/internal.rb, line 11
11: def response_for(action)
12: respond_to do |wants|
13: options_for(action).response.each do |method, block|
14: if block.nil?
15: wants.send(method)
16: else
17: wants.send(method) { instance_eval(&block) }
18: end
19: end
20: end
21: end
Sets the flash and flash_now for the action, if it is present.
# File ../lib/resource_controller/helpers/internal.rb, line 37
37: def set_flash(action)
38: set_normal_flash(action)
39: set_flash_now(action)
40: end
Sets the flash.now (i.e. flash.now[:notice] = ’…’)
# File ../lib/resource_controller/helpers/internal.rb, line 52
52: def set_flash_now(action)
53: if f = options_for(action).flash_now
54: flash.now[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash_now
55: end
56: end