Class: Merb::AbstractController
- Inherits:
-
Object
- Object
- Merb::AbstractController
- Defined in:
- lib/merb-action-args/abstract_controller.rb
Class Attribute Summary collapse
-
.action_argument_list ⇒ Object
Returns the value of attribute action_argument_list.
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Stores the argument lists for all methods for this class.
- .old_inherited ⇒ Object
Instance Method Summary collapse
-
#_call_action(action) ⇒ Object
Calls an action and maps the params hash to the action parameters.
Class Attribute Details
.action_argument_list ⇒ Object
Returns the value of attribute action_argument_list.
4 5 6 |
# File 'lib/merb-action-args/abstract_controller.rb', line 4 def action_argument_list @action_argument_list end |
Class Method Details
.inherited(klass) ⇒ Object
Stores the argument lists for all methods for this class.
Parameters
- klass<Class>
-
The controller that is being inherited from Merb::AbstractController.
12 13 14 15 16 17 |
# File 'lib/merb-action-args/abstract_controller.rb', line 12 def inherited(klass) klass.action_argument_list = Hash.new do |h,k| h[k] = ParseTreeArray.translate(klass, k.to_sym).get_args end old_inherited(klass) end |
.old_inherited ⇒ Object
5 |
# File 'lib/merb-action-args/abstract_controller.rb', line 5 alias_method :old_inherited, :inherited |
Instance Method Details
#_call_action(action) ⇒ Object
Calls an action and maps the params hash to the action parameters.
Parameters
- action<Symbol>
-
The action to call
Raises
- BadRequest
-
The params hash doesn’t have a required parameter.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/merb-action-args/abstract_controller.rb', line 27 def _call_action(action) arguments, defaults = self.class.action_argument_list[action] args = arguments.map do |arg, default| arg = arg p = params.key?(arg.to_sym) raise BadRequest unless p || (defaults && defaults.include?(arg)) p ? params[arg.to_sym] : default end __send__(action, *args) end |