Module: ActionArgs::ActiveSupport::CallbackParameterizer

Defined in:
lib/action_args/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#make_lambdaObject

Extending AS::Callbacks::Callback's `make_lambda` not just to call specified method but to call the method with method parameters taken from `params`. This would happen only when

  • the target object is_a ActionController object

  • the filter was not defined via lambda



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/action_args/callbacks.rb', line 35

def make_lambda
  lambda do |target, value, &block|
    target, block, method, *arguments = expand(target, value, block)

    if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
      target.strengthen_params! method
      arguments, keyword_arguments = target.extract_method_arguments_from_params method
      if keyword_arguments.any?
        target.send(method, *arguments, **keyword_arguments, &block)
      else
        target.send(method, *arguments, &block)
      end
    else
      target.send(method, *arguments, &block)
    end
  end
end