Module: AbstractController::ActionArgs::ClassMethods
- Defined in:
- lib/rails_action_args/abstract_controller.rb
Instance Method Summary collapse
-
#action_args_for(action_name, params) ⇒ Object
:api: private.
-
#extract_action_args_for(action_name) ⇒ Object
:api: private.
Instance Method Details
#action_args_for(action_name, params) ⇒ Object
:api: private
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_action_args/abstract_controller.rb', line 24 def action_args_for(action_name, params) arguments, defaults = extract_action_args_for(action_name) arguments.map do |arg, default| arg = arg param = params.key?(arg.to_sym) unless param || (defaults && defaults.include?(arg)) raise InvalidActionArgs.new("No value or default value supplied for action arg: #{arg}") else param ? params[arg.to_sym] : default end end end |
#extract_action_args_for(action_name) ⇒ Object
:api: private
39 40 41 42 43 44 45 |
# File 'lib/rails_action_args/abstract_controller.rb', line 39 def extract_action_args_for(action_name) args = instance_method(action_name).get_args arguments = args[0] defaults = [] arguments.each {|a| defaults << a[0] if a.size == 2} if arguments [arguments || [], defaults] end |