Module: ActionArgs::ActiveSupport::CallbackParameterizer

Included in:
ActiveSupport::Callbacks::CallTemplate
Defined in:
lib/action_args/callbacks.rb

Overview

For Rails >= 5.1

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/action_args/callbacks.rb', line 14

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