Class: ActiveSupport::Callbacks::Callback
- Inherits:
-
Object
- Object
- ActiveSupport::Callbacks::Callback
- Defined in:
- lib/action_args/callbacks.rb
Instance Method Summary collapse
- #apply_with_method_parameters(code) ⇒ Object
-
#make_lambda_with_method_parameters(filter) ⇒ Object
Extending AS::Callbacks::Callback's
make_lambdanot just to call specified method but to call the method with method parameters taken fromparams. -
#start_with_method_parameters(key = nil, object = nil) ⇒ Object
Rails 3.2.
Instance Method Details
#apply_with_method_parameters(code) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/action_args/callbacks.rb', line 30 def apply_with_method_parameters(code) if (Symbol === @filter) && (@klass < ActionController::Base) method_body = <<-FILTER meth = method :#{@filter} method_parameters = meth.parameters ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params) values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, params send :#{@filter}, *values FILTER if @kind == :before @filter = "begin\n#{method_body}\nend" else @filter = method_body.chomp end end apply_without_method_parameters code end |
#make_lambda_with_method_parameters(filter) ⇒ Object
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 filter was defined in Symbol form
- the target object is_a ActionController object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/action_args/callbacks.rb', line 10 def make_lambda_with_method_parameters(filter) if Symbol === filter lambda do |target, _, &blk| if ActionController::Base === target meth = target.method filter method_parameters = meth.parameters ActionArgs::ParamsHandler.strengthen_params!(target.class, method_parameters, target.params) values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, target.params target.send filter, *values, &blk else target.send filter, &blk end end else make_lambda_without_method_parameters filter end end |
#start_with_method_parameters(key = nil, object = nil) ⇒ Object
Rails 3.2
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/action_args/callbacks.rb', line 50 def start_with_method_parameters(key=nil, object=nil) if (Symbol === @filter) && (@klass < ActionController::Base) method_body = <<-FILTER meth = method :#{@filter} method_parameters = meth.parameters ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params) values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method_parameters, params send :#{@filter}, *values FILTER if @kind == :before @filter = "begin\n#{method_body}\nend" else @filter = method_body.chomp end end start_without_method_parameters key, object end |