action_args 2.3.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 234e515eeed335a94bc99891422b4e0374227c9d18b0cd5dcab10dc5c86a8ee2
4
- data.tar.gz: bab6cf038df32ccc98d4921bda15b4815f039660219c8430fbf5a5f293be1cd9
3
+ metadata.gz: 6622f79d42d59b8e4ac5da4090a0f135246157e38db10662c20bc17269fa343a
4
+ data.tar.gz: 1e20928a79311c79a5cab6028956519a21477c567ecd0f3b7c41c95919fa7043
5
5
  SHA512:
6
- metadata.gz: 143f8be57fe2a24ff9ad59abc21433a3248cc64536fbdd4b2b72dbf3fcb7df4f86be0655f543e696db4b909a789e189ed7b3377b27ac5c8a9082d9d4c3546558
7
- data.tar.gz: 8627eb5561b52f110be725779eea1382fdd9453755d7cae01ba2f7fb4b87bcd77e0207466acc15b62c9ac4f323d6688dabce8a646dfe050924f75ae43d1709df
6
+ metadata.gz: 40ed64f0cacf2a3c787c164967804a00f5644a575231da58274605386ff3cfdf1a00a8866b2f509106940352e90abcd130298c0a654ccaabc6dfef614b6497fc
7
+ data.tar.gz: 8cf743239b588cdf6f4af6175b3218679d78b96ad433993b14c3b4c72b2ff31934d22e9fa16a36b5f2155dd9de7b920cfdf0ffb017666fa32338e81b21152025
@@ -0,0 +1,88 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ include:
10
+ - ruby_version: ruby-head
11
+ gemfile: gemfiles/rails_edge.gemfile
12
+ allow_failures: 'true'
13
+ - ruby_version: '3.0'
14
+ gemfile: gemfiles/rails_70.gemfile
15
+ allow_failures: 'true'
16
+ - ruby_version: '3.0'
17
+ gemfile: gemfiles/rails_61.gemfile
18
+ allow_failures: 'true'
19
+
20
+ - ruby_version: '3.0'
21
+ gemfile: gemfiles/rails_edge.gemfile
22
+ allow_failures: 'true'
23
+ - ruby_version: '3.0'
24
+ gemfile: gemfiles/rails_70.gemfile
25
+ - ruby_version: '3.0'
26
+ gemfile: gemfiles/rails_61.gemfile
27
+ - ruby_version: '3.0'
28
+ gemfile: gemfiles/rails_60.gemfile
29
+
30
+ - ruby_version: jruby
31
+ gemfile: gemfiles/rails_61.gemfile
32
+ allow_failures: 'true'
33
+ - ruby_version: jruby
34
+ gemfile: gemfiles/rails_70.gemfile
35
+ allow_failures: 'true'
36
+
37
+ - ruby_version: '2.7'
38
+ gemfile: gemfiles/rails_edge.gemfile
39
+ allow_failures: 'true'
40
+ - ruby_version: '2.7'
41
+ gemfile: gemfiles/rails_70.gemfile
42
+ - ruby_version: '2.7'
43
+ gemfile: gemfiles/rails_61.gemfile
44
+
45
+ - ruby_version: '2.6'
46
+ gemfile: gemfiles/rails_61.gemfile
47
+ - ruby_version: '2.6'
48
+ gemfile: gemfiles/rails_52.gemfile
49
+ - ruby_version: '2.6'
50
+ gemfile: gemfiles/rails_51.gemfile
51
+ - ruby_version: '2.6'
52
+ gemfile: gemfiles/rails_50.gemfile
53
+
54
+ - ruby_version: '2.5'
55
+ gemfile: gemfiles/rails_61.gemfile
56
+ - ruby_version: '2.5'
57
+ gemfile: gemfiles/rails_52.gemfile
58
+
59
+ - ruby_version: '2.4'
60
+ gemfile: gemfiles/rails_52.gemfile
61
+
62
+ - ruby_version: '2.3'
63
+ gemfile: gemfiles/rails_52.gemfile
64
+
65
+ - ruby_version: '2.2'
66
+ gemfile: gemfiles/rails_42.gemfile
67
+ - ruby_version: '2.2'
68
+ gemfile: gemfiles/rails_41.gemfile
69
+
70
+ - ruby_version: '2.1'
71
+ gemfile: gemfiles/rails_42.gemfile
72
+
73
+ runs-on: ubuntu-latest
74
+
75
+ env:
76
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
77
+
78
+ steps:
79
+ - uses: actions/checkout@v2
80
+
81
+ - uses: ruby/setup-ruby@v1
82
+ with:
83
+ ruby-version: ${{ matrix.ruby_version }}
84
+ bundler-cache: true
85
+ continue-on-error: ${{ matrix.allow_failures == 'true' }}
86
+
87
+ - run: bundle exec rake
88
+ continue-on-error: ${{ matrix.allow_failures == 'true' }}
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # ActionArgs
2
- [![Build Status](https://travis-ci.org/asakusarb/action_args.svg?branch=master)](https://travis-ci.org/asakusarb/action_args)
1
+ # action_args
2
+ [![Build Status](https://github.com/asakusarb/action_args/actions/workflows/main.yml/badge.svg)](https://github.com/asakusarb/action_args/actions/actions)
3
3
 
4
- Controller action arguments parameterizer for Rails 4.1+
4
+ Controller action arguments parameterizer for Rails
5
5
 
6
6
 
7
- ## What is this?
7
+ ## What Is This?
8
8
 
9
- ActionArgs is a Rails plugin that extends your controller action methods to allow you to specify arguments of interest in the method definition for any action. - in short, Merbish.
9
+ action_args is a Rails plugin that extends your controller action methods to allow you to specify arguments of interest in the method definition for any action. - in short, this makes your Rails controller Merb-ish.
10
10
 
11
11
 
12
12
  ## The Controllers
@@ -14,24 +14,24 @@ ActionArgs is a Rails plugin that extends your controller action methods to allo
14
14
  Having the following controller code:
15
15
 
16
16
  ```ruby
17
- class HogeController < ApplicationController
18
- def fuga(piyo)
19
- render :text => piyo
17
+ class UsersController < ApplicationController
18
+ def show(id)
19
+ @user = User.find id
20
20
  end
21
21
  end
22
22
  ```
23
23
 
24
- Hitting "/hoge/fuga?piyo=foo" will call `fuga('foo')` and output 'foo'.
25
- This allows you to explicitly state which members of the `params` Hash are used in your controller actions.
24
+ When a request visits "/users/777", it calls `UsersController#show` passing 777 as the method parameter.
25
+ This allows you to explicitly state the most important API for the action -- which members of the `params` Hash are used in your controller actions -- in a perfectly natural Ruby way!
26
26
 
27
27
 
28
- ## Method parameter types in Ruby, and how ActionArgs handles parameters
28
+ ## Method Parameter Types in Ruby, and How action_args Handles Parameters
29
29
 
30
30
  ### Required Parameters (:req)
31
- Method parameters that you specify are required. If a key of the same name does not exist in the params Hash,
32
- ActionContrller::BadRequest is raised.
31
+ Method parameters that you specify are required. If a key of the same name does not exist in the params Hash, ActionContrller::BadRequest is raised.
32
+
33
+ In this `show` action, action_args will require that `id` parameter is provided.
33
34
 
34
- In this `show` action, ActionArgs will require that `id` parameter is provided.
35
35
  ```ruby
36
36
  class UsersController < ApplicationController
37
37
  # the `id` parameter is mandatory
@@ -55,7 +55,7 @@ end
55
55
 
56
56
  ### Keyword Argument (:key)
57
57
  If you think this Ruby 2.0 syntax reads better, you can choose this style for defining your action methods.
58
- This just works in the same way as :opt here.
58
+ This just works in the same way as `:opt` here.
59
59
 
60
60
  ```ruby
61
61
  class UsersController < ApplicationController
@@ -67,8 +67,8 @@ end
67
67
  ```
68
68
 
69
69
  ### Required Keyword Argument (:keyreq)
70
- :keyreq is the required version of :key, which was introduced in Ruby 2.1.
71
- You can use this syntax instead of :req.
70
+ `:keyreq` is the required version of `:key`, which was introduced in Ruby 2.1.
71
+ You can use this syntax instead of `:req`.
72
72
 
73
73
  ```ruby
74
74
  class CommentsController < ApplicationController
@@ -80,9 +80,9 @@ class CommentsController < ApplicationController
80
80
  end
81
81
  ```
82
82
 
83
- ### StrongParameters - permit
83
+ ## StrongParameters - permit
84
84
 
85
- ActionArgs plays very nice with Rails 4 StrongParameters.
85
+ action_args plays very nice with Rails 4 StrongParameters.
86
86
 
87
87
  1. Inline declaration
88
88
 
@@ -97,17 +97,17 @@ class UsersController < ApplicationController
97
97
  end
98
98
  ```
99
99
 
100
- 2. Declarative white-listing
100
+ 2. Declarative allow-listing
101
101
 
102
- ActionArgs also provides a declarative `permits` method for controller classes.
102
+ action_args also provides a declarative `permits` method for controller classes.
103
103
  Use this to keep your `permit` calls DRY in a comprehensible way.
104
104
 
105
105
  ```ruby
106
106
  class UsersController < ApplicationController
107
- # white-lists User model's attributes
107
+ # allow-lists User model's attributes
108
108
  permits :name, :age
109
109
 
110
- # the given `user` parameter would be automatically permitted by ActionArgs
110
+ # the given `user` parameter would be automatically permitted by action_args
111
111
  def create(user)
112
112
  @user = User.new(user)
113
113
  end
@@ -116,18 +116,19 @@ end
116
116
 
117
117
  By default, action_args deduces the target model name from the controller name.
118
118
  For example, the `permits` call in `UsersController` expects the model name to be `User`.
119
- If this is not the case, you can specify the :model_name option:
119
+ If this is not the case, you can specify the `:model_name` option:
120
120
 
121
121
  ```ruby
122
122
  class MembersController < ApplicationController
123
- # white-lists User model's attributes
123
+ # allow-lists User model's attributes
124
124
  permits :name, :age, model_name: 'User'
125
125
  end
126
126
  ```
127
127
 
128
+
128
129
  ## Filters
129
130
 
130
- ActionArgs works in filters, in the same way as it works in controller actions.
131
+ action_args works in filters, in the same way as it works in controller actions.
131
132
 
132
133
  ```ruby
133
134
  class UsersController < ApplicationController
@@ -136,17 +137,44 @@ class UsersController < ApplicationController
136
137
  def show
137
138
  end
138
139
 
139
- private
140
- # `params[:id]` will be dynamically assigned to the method parameter `id` here
141
- def set_user(id)
142
- @user = User.find(id)
143
- end
140
+ # `params[:id]` will be dynamically assigned to the method parameter `id` here
141
+ private def set_user(id)
142
+ @user = User.find(id)
143
+ end
144
144
  end
145
145
  ```
146
146
 
147
+
148
+ ## The *_params Convention
149
+
150
+ For those who are familiar with the Rails scaffold's default naming style, you can add `_params` suffix to any of the parameter names in the method signatures.
151
+ It just matches with the params name without `_params`.
152
+
153
+ For instance, these two actions both pass `params[:user]` as the method parameter.
154
+
155
+ ```ruby
156
+ # without _params
157
+ def create(user)
158
+ @user = User.new(user)
159
+ ...
160
+ end
161
+ ```
162
+
163
+ ```ruby
164
+ # with _params
165
+ def create(user_params)
166
+ @user = User.new(user_params)
167
+ ...
168
+ end
169
+ ```
170
+
171
+ This naming convention makes your controller code look much more compatible with the Rails' default scaffolded code,
172
+ and so it may be actually super easy for you to manually migrate from the legacy scaffold controller to the action_args style.
173
+
174
+
147
175
  ## The Scaffold Generator
148
176
 
149
- ActionArgs provides a custom scaffold controller generator that overwrites the default scaffold generator.
177
+ action_args provides a custom scaffold controller generator that overwrites the default scaffold generator.
150
178
  Thus, by hitting the scaffold generator command like this:
151
179
 
152
180
  ```sh
@@ -212,37 +240,33 @@ end
212
240
  ```
213
241
 
214
242
  You may notice that
215
- * There are no globalish `params` reference
243
+ * There are no global-ish `params` reference
216
244
  * It's quite easy to comprehend what's the actual input value for each action
217
- * You may write the unit test code as if the actions are just normal Ruby methods
245
+ * You may be able to write the unit test code without mocking `params` as if the actions are just normal Ruby methods
218
246
 
219
247
 
220
- ## Supported versions
248
+ ## Supported Versions
221
249
 
222
- * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.0 (trunk), JRuby, & Rubinius with 2.0+ mode
250
+ * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, 3.1 (trunk), JRuby, & Rubinius with 2.0+ mode
223
251
 
224
- * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0 (edge)
252
+ * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0 (edge)
225
253
 
226
- Please use Version 1.5.4 for Rails 4.0.x.
254
+ For Rails 4.0.x, please use Version 1.5.4.
227
255
 
228
256
 
229
257
  ## Installation
230
258
 
231
- Put this line in your Gemfile:
259
+ Bundle the gem to your Rails app by putting this line in your Gemfile:
260
+
232
261
  ```ruby
233
262
  gem 'action_args'
234
263
  ```
235
264
 
236
- Then bundle:
237
- ```sh
238
- % bundle
239
- ```
240
-
241
265
  ## Notes
242
266
 
243
267
  ### Plain Old Action Methods
244
268
 
245
- Of course you still can use both Merbish style and plain old Rails style action methods even if this plugin is loaded. `params` parameter is still alive as well. That means, this plugin won't break any existing controller API.
269
+ Of course you still can use both Merb-like style and plain old Rails style action methods even if this plugin is loaded. `params` parameter is still alive as well. That means, this plugin won't break any existing controller API.
246
270
 
247
271
  ### Argument Naming Convention
248
272
 
@@ -264,7 +288,7 @@ class BooksController < ApplicationController
264
288
  end
265
289
  ```
266
290
 
267
- ### Default parameter values
291
+ ### Default Parameter Values
268
292
 
269
293
  You are of course able to specify default values for action parameters such as:
270
294
 
@@ -290,6 +314,7 @@ end
290
314
 
291
315
  This way, the `page` parameter will be defaulted to 1 as everyone might expect.
292
316
 
317
+
293
318
  ## Copyright
294
319
 
295
320
  Copyright (c) 2011- Asakusa.rb. See MIT-LICENSE for further details.
data/Rakefile CHANGED
@@ -10,22 +10,4 @@ Rake::TestTask.new do |t|
10
10
  t.verbose = true
11
11
  end
12
12
 
13
- task :default => 'test:all'
14
-
15
- namespace :test do
16
- %w(rails_41 rails_42 rails_edge).each do |gemfile|
17
- desc "Run Tests against #{gemfile}"
18
- task gemfile do
19
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
20
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t test"
21
- end
22
- end
23
-
24
- desc 'Run Tests against all Rails versions'
25
- task :all do
26
- %w(rails_41 rails_42 rails_edge).each do |gemfile|
27
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
28
- sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t test"
29
- end
30
- end
31
- end
13
+ task default: :test
data/action_args.gemspec CHANGED
@@ -12,12 +12,15 @@ Gem::Specification.new do |s|
12
12
  s.email = ['ronnie@dio.jp']
13
13
  s.homepage = 'http://asakusa.rubyist.net/'
14
14
  s.license = 'MIT'
15
+ s.metadata = {
16
+ 'source_code_uri' => 'https://github.com/asakusarb/action_args'
17
+ }
15
18
  s.summary = 'Controller action arguments parameterizer for Rails 4+ & Ruby 2.0+'
16
19
  s.description = 'Rails plugin gem that supports Merbish style controller action arguments.'
17
20
 
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
21
24
  s.require_paths = ["lib"]
22
25
 
23
26
  s.add_development_dependency 'bundler'
@@ -8,7 +8,7 @@ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
8
8
  gemspec :path => '../'
9
9
 
10
10
  platforms :ruby do
11
- gem 'sqlite3'
11
+ gem 'sqlite3', '~> 1.3.6'
12
12
  end
13
13
 
14
14
  platforms :jruby do
@@ -8,7 +8,7 @@ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
8
8
  gemspec :path => '../'
9
9
 
10
10
  platforms :ruby do
11
- gem 'sqlite3'
11
+ gem 'sqlite3', '~> 1.3.6'
12
12
  end
13
13
 
14
14
  platforms :jruby do
@@ -4,12 +4,10 @@ source 'https://rubygems.org'
4
4
 
5
5
  gem 'rails', '~> 5.0.1'
6
6
 
7
- gem 'rails-controller-testing'
8
-
9
7
  gemspec :path => '../'
10
8
 
11
9
  platforms :ruby do
12
- gem 'sqlite3'
10
+ gem 'sqlite3', '~> 1.3.6'
13
11
  end
14
12
 
15
13
  platforms :jruby do
@@ -4,12 +4,10 @@ source 'https://rubygems.org'
4
4
 
5
5
  gem 'rails', '~> 5.1.0'
6
6
 
7
- gem 'rails-controller-testing'
8
-
9
7
  gemspec :path => '../'
10
8
 
11
9
  platforms :ruby do
12
- gem 'sqlite3'
10
+ gem 'sqlite3', '~> 1.3.6'
13
11
  end
14
12
 
15
13
  platforms :jruby do
@@ -4,12 +4,10 @@ source 'https://rubygems.org'
4
4
 
5
5
  gem 'rails', '~> 5.2.0'
6
6
 
7
- gem 'rails-controller-testing'
8
-
9
7
  gemspec :path => '../'
10
8
 
11
9
  platforms :ruby do
12
- gem 'sqlite3'
10
+ gem 'sqlite3', '~> 1.3.6'
13
11
  end
14
12
 
15
13
  platforms :jruby do
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 6.0.0'
6
+ gem 'selenium-webdriver'
7
+
8
+ gemspec path: '../'
9
+
10
+ platforms :ruby do
11
+ gem 'sqlite3'
12
+ end
13
+
14
+ platforms :jruby do
15
+ gem 'activerecord-jdbcsqlite3-adapter'
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 6.1.0'
6
+ gem 'selenium-webdriver'
7
+
8
+ gemspec path: '../'
9
+
10
+ platforms :ruby do
11
+ gem 'sqlite3'
12
+ end
13
+
14
+ platforms :jruby do
15
+ gem 'activerecord-jdbcsqlite3-adapter'
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 7.0.0'
6
+ gem 'net-smtp'
7
+ gem 'selenium-webdriver'
8
+
9
+ gemspec path: '../'
10
+
11
+ platforms :ruby do
12
+ gem 'sqlite3'
13
+ end
14
+
15
+ platforms :jruby do
16
+ gem 'activerecord-jdbcsqlite3-adapter'
17
+ end
@@ -7,11 +7,8 @@ git_source(:github) do |repo_name|
7
7
  end
8
8
 
9
9
  gem 'rails', github: 'rails/rails'
10
- gem 'rack', github: 'rack/rack'
11
- gem 'arel', github: 'rails/arel'
12
- gem 'sprockets', github: 'rails/sprockets'
13
- gem 'sprockets-rails', github: 'rails/sprockets-rails'
14
- gem 'rails-controller-testing'
10
+ gem 'net-smtp'
11
+ gem 'selenium-webdriver'
15
12
 
16
13
  gemspec :path => '../'
17
14
 
@@ -10,8 +10,12 @@ module ActionArgs
10
10
  return super if !defined?(params) || params.nil?
11
11
 
12
12
  strengthen_params! method_name
13
- values = extract_method_arguments_from_params method_name
14
- super method_name, *values
13
+ values, kwargs_values = extract_method_arguments_from_params method_name
14
+ if kwargs_values.any?
15
+ super method_name, *values, **kwargs_values
16
+ else
17
+ super method_name, *values
18
+ end
15
19
  end
16
20
  end
17
21
 
@@ -4,65 +4,81 @@ using ActionArgs::ParamsHandler
4
4
 
5
5
  module ActionArgs
6
6
  module ActiveSupport
7
- # For Rails >= 5.1
8
- module CallbackParameterizer
9
- # Extending AS::Callbacks::Callback's `expand` not just to call specified
10
- # method but to call the method with method parameters taken from `params`.
11
- # This would happen only when
12
- # * the target object is_a ActionController object
13
- # * the filter was not defined via lambda
14
- def expand(*)
15
- target, block, method, *arguments = super
16
-
17
- if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
18
- target.strengthen_params! method
19
- arguments = target.extract_method_arguments_from_params method
7
+ if Rails::VERSION::MAJOR >= 7
8
+ module CallTemplate
9
+ module MethodCallParameterizer
10
+ def make_lambda
11
+ lambda do |target, value, &block|
12
+ if ActionController::Base === target
13
+ target.strengthen_params! @method_name
14
+ arguments, keyword_arguments = target.extract_method_arguments_from_params @method_name
15
+ if keyword_arguments.any?
16
+ target.send(@method_name, *arguments, **keyword_arguments, &block)
17
+ else
18
+ target.send(@method_name, *arguments, &block)
19
+ end
20
+ else
21
+ lambda do |target, value, &block|
22
+ target.send(@method_name, &block)
23
+ end
24
+ end
25
+ end
26
+ end
20
27
  end
21
-
22
- [target, block, method, *arguments]
23
28
  end
24
- end
29
+ ::ActiveSupport::Callbacks::CallTemplate::MethodCall.prepend ActionArgs::ActiveSupport::CallTemplate::MethodCallParameterizer
30
+ elsif Rails.version >= '5.1'
31
+ module CallbackParameterizer
32
+ # Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
33
+ # method but to call the method with method parameters taken from `params`.
34
+ # This would happen only when
35
+ # * the target object is_a ActionController object
36
+ # * the filter was not defined via lambda
37
+ def make_lambda
38
+ lambda do |target, value, &block|
39
+ target, block, method, *arguments = expand(target, value, block)
25
40
 
26
- # For Rails 4 & 5.0
27
- module CallbackParameterizerLegacy
28
- # Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
29
- # method but to call the method with method parameters taken from `params`.
30
- # This would happen only when
31
- # * the filter was defined in Symbol form
32
- # * the target object is_a ActionController object
33
- def make_lambda(filter)
34
- if Symbol === filter
35
- lambda do |target, _, &blk|
36
- if ActionController::Base === target
37
- target.strengthen_params! filter
38
- values = target.extract_method_arguments_from_params filter
39
- target.send filter, *values, &blk
41
+ if (ActionController::Base === target) && (method != :instance_exec) && arguments.empty?
42
+ target.strengthen_params! method
43
+ arguments, keyword_arguments = target.extract_method_arguments_from_params method
44
+ if keyword_arguments.any?
45
+ target.send(method, *arguments, **keyword_arguments, &block)
46
+ else
47
+ target.send(method, *arguments, &block)
48
+ end
40
49
  else
41
- target.send filter, &blk
50
+ target.send(method, *arguments, &block)
42
51
  end
43
52
  end
44
- else
45
- super
46
53
  end
47
54
  end
48
- end
49
- end
50
- end
51
-
52
- if Rails.version >= '5.1'
53
- module ActiveSupport
54
- module Callbacks
55
- class CallTemplate
56
- prepend ActionArgs::ActiveSupport::CallbackParameterizer
57
- end
58
- end
59
- end
60
- else
61
- module ActiveSupport
62
- module Callbacks
63
- class Callback
64
- prepend ActionArgs::ActiveSupport::CallbackParameterizerLegacy
55
+ ::ActiveSupport::Callbacks::CallTemplate.prepend ActionArgs::ActiveSupport::CallbackParameterizer
56
+ else
57
+ # For Rails 4 & 5.0
58
+ module CallbackParameterizerLegacy
59
+ # Extending AS::Callbacks::Callback's `make_lambda` not just to call specified
60
+ # method but to call the method with method parameters taken from `params`.
61
+ # This would happen only when
62
+ # * the filter was defined in Symbol form
63
+ # * the target object is_a ActionController object
64
+ def make_lambda(filter)
65
+ if Symbol === filter
66
+ lambda do |target, _, &blk|
67
+ if ActionController::Base === target
68
+ target.strengthen_params! filter
69
+ values, kwargs_values = target.extract_method_arguments_from_params filter
70
+ values << kwargs_values if kwargs_values.any?
71
+ target.send filter, *values, &blk
72
+ else
73
+ target.send filter, &blk
74
+ end
75
+ end
76
+ else
77
+ super
78
+ end
79
+ end
65
80
  end
81
+ ::ActiveSupport::Callbacks::Callback.prepend ActionArgs::ActiveSupport::CallbackParameterizerLegacy
66
82
  end
67
83
  end
68
84
  end