action_args 1.1.0 → 1.1.1
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 +4 -4
- data/README.md +20 -14
- data/gemfiles/rails_40.gemfile +1 -3
- data/lib/action_args/abstract_controller.rb +2 -0
- data/lib/action_args/version.rb +1 -1
- data/spec/fake_app.rb +13 -0
- data/spec/mailers/action_mailer_spec.rb +9 -0
- data/spec/params_handler/params_handler_spec.rb +10 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc1d9d90cd395b886fc828a35a63c5d0064af53
|
4
|
+
data.tar.gz: 15bbdff4daa2bfa5413ed8a1a14f54770359fd87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03ab97f8deb9229b3c1c158ad0d4a414324e848665c8ee3bf090dc4d9367a3bdf87d9991b9c054ae19436201dd10f942b1b401200d2b16949af994c2e1789c98
|
7
|
+
data.tar.gz: d1e480e53600b3a14e39741c85678f76fc8f3f1c3dba7a31b3fd27c9b1a5c7b40e911cfe37200e19e8dd7e05a5fa60b48ddc2789cbc93aefd6482f21c9ac6ea8
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# ActionArgs
|
2
2
|
|
3
|
-
Controller action arguments parameterizer for Rails 3
|
3
|
+
Controller action arguments parameterizer for Rails 3 and 4
|
4
4
|
|
5
5
|
|
6
6
|
## What is this?
|
7
7
|
|
8
|
-
ActionArgs is a Rails plugin that extends your controller action methods to
|
8
|
+
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
9
|
|
10
10
|
|
11
11
|
## The Controllers
|
@@ -21,16 +21,18 @@ end
|
|
21
21
|
```
|
22
22
|
|
23
23
|
Hitting "/hoge/fuga?piyo=foo" will call `fuga('foo')` and output 'foo'.
|
24
|
-
|
24
|
+
This allows you to explicitly state which members of the `params` Hash are used in your controller actions,
|
25
25
|
|
26
26
|
|
27
27
|
## StrongParameters
|
28
28
|
|
29
29
|
ActionArgs plays very nice with Rails 4 StrongParameters.
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
### Required Parameters
|
32
|
+
Method parameters that you specify are required. If a key of the same name does not exist in the params Hash,
|
33
|
+
an ArgumentError is raised.
|
33
34
|
|
35
|
+
In this `show` action, ActionArgs will require that `id` parameter is provided.
|
34
36
|
```ruby
|
35
37
|
class UsersController < ApplicationController
|
36
38
|
# the `id` parameter is mandatory
|
@@ -40,8 +42,8 @@ class UsersController < ApplicationController
|
|
40
42
|
end
|
41
43
|
```
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
### Optional Parameters
|
46
|
+
Default parameter values are assigned in the standard way. Parameters with a default value will not require a matching item in the `params` Hash.
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
class UsersController < ApplicationController
|
@@ -52,7 +54,11 @@ class UsersController < ApplicationController
|
|
52
54
|
end
|
53
55
|
```
|
54
56
|
|
55
|
-
|
57
|
+
### StrongParameters - permit
|
58
|
+
|
59
|
+
1. Inline declaration
|
60
|
+
|
61
|
+
Hashes simply respond to the StrongParameters' `permit` method.
|
56
62
|
|
57
63
|
```ruby
|
58
64
|
class UsersController < ApplicationController
|
@@ -63,10 +69,10 @@ class UsersController < ApplicationController
|
|
63
69
|
end
|
64
70
|
```
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
`permit`
|
72
|
+
2. Declarative white-listing
|
73
|
+
|
74
|
+
ActionArgs also provides a declarative `permits` method for controller classes.
|
75
|
+
Use this to keep your `permit` calls DRY in a comprehensible way.
|
70
76
|
|
71
77
|
```ruby
|
72
78
|
class UsersController < ApplicationController
|
@@ -213,7 +219,7 @@ class BooksController < ApplicationController
|
|
213
219
|
end
|
214
220
|
```
|
215
221
|
|
216
|
-
However, due to some
|
222
|
+
However, due to some implementation reasons, the `page` variable will be actually defaulted to nil when `page` parameter was not given.
|
217
223
|
|
218
224
|
In order to provide default parameter values in perfect Ruby manner, we recommend you to use the Ruby 2.0 "keyword arguments" syntax instead.
|
219
225
|
|
@@ -229,4 +235,4 @@ This way, the `page` parameter will be defaulted to 1 as everyone might expect.
|
|
229
235
|
|
230
236
|
## Copyright
|
231
237
|
|
232
|
-
Copyright (c) 2011 Asakusa.rb. See MIT-LICENSE for further details.
|
238
|
+
Copyright (c) 2011~2013 Asakusa.rb. See MIT-LICENSE for further details.
|
data/gemfiles/rails_40.gemfile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails',
|
4
|
-
gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
|
5
|
-
gem 'journey', github: 'rails/journey'
|
3
|
+
gem 'rails', '>= 4.0.0'
|
6
4
|
gem 'rspec-rails', '>= 2.0'
|
7
5
|
|
8
6
|
gemspec :path => '../'
|
@@ -3,6 +3,7 @@ module AbstractController
|
|
3
3
|
if defined? ActionController::StrongParameters
|
4
4
|
def send_action(method_name, *args)
|
5
5
|
return send method_name, *args unless args.empty?
|
6
|
+
return send method_name, *args unless defined?(params)
|
6
7
|
|
7
8
|
method_parameters = method(method_name).parameters
|
8
9
|
ActionArgs::ParamsHandler.strengthen_params!(self.class, method_parameters, params)
|
@@ -29,6 +30,7 @@ module AbstractController
|
|
29
30
|
else
|
30
31
|
def send_action(method_name, *args)
|
31
32
|
return send method_name, *args unless args.empty?
|
33
|
+
return send method_name, *args unless defined?(params)
|
32
34
|
|
33
35
|
values = ActionArgs::ParamsHandler.extract_method_arguments_from_params method(method_name).parameters, params
|
34
36
|
send method_name, *values
|
data/lib/action_args/version.rb
CHANGED
data/spec/fake_app.rb
CHANGED
@@ -31,6 +31,19 @@ end
|
|
31
31
|
class Store < ActiveRecord::Base
|
32
32
|
end
|
33
33
|
|
34
|
+
# mailers
|
35
|
+
require "action_mailer/railtie"
|
36
|
+
class UserMailer < ActionMailer::Base
|
37
|
+
def send_email_without_args
|
38
|
+
mail(
|
39
|
+
to: 'to@example.com',
|
40
|
+
from: 'from@example.com',
|
41
|
+
subject: 'Action Args!!!',
|
42
|
+
body: 'test'
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
34
47
|
# helpers
|
35
48
|
module ApplicationHelper; end
|
36
49
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UserMailer do
|
4
|
+
describe '#send_email_without_args' do
|
5
|
+
it "should not raise NameError: undefined local variable or method `params' for ..." do
|
6
|
+
expect{ UserMailer.send_email_without_args }.to_not raise_error(NameError)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -146,12 +146,16 @@ describe ActionArgs::ParamsHandler do
|
|
146
146
|
its([:b]) { should be }
|
147
147
|
end
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
if RUBY_VERSION >= '2'
|
150
|
+
eval <<-KWARGS_TEST
|
151
|
+
context 'requiring via :key, permitting all scalars' do
|
152
|
+
let(:controller) { FugaController ||= Class.new(ApplicationController) { permits :a, :b; def a(fuga: {}) end } }
|
153
|
+
subject { params[:fuga] }
|
154
|
+
it { should be_permitted }
|
155
|
+
its([:a]) { should be }
|
156
|
+
its([:b]) { should be }
|
157
|
+
end
|
158
|
+
KWARGS_TEST
|
155
159
|
end
|
156
160
|
end
|
157
161
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_args
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails plugin gem that supports Merbish style controller action arguments.
|
14
14
|
email:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- spec/controllers/strong_parameters_spec.rb
|
41
41
|
- spec/fake_app.rb
|
42
42
|
- spec/kwargs_controllers.rb
|
43
|
+
- spec/mailers/action_mailer_spec.rb
|
43
44
|
- spec/params_handler/params_handler_spec.rb
|
44
45
|
- spec/spec_helper.rb
|
45
46
|
homepage: http://asakusa.rubyist.net/
|
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
version: '0'
|
62
63
|
requirements: []
|
63
64
|
rubyforge_project: action_args
|
64
|
-
rubygems_version: 2.0.
|
65
|
+
rubygems_version: 2.0.3
|
65
66
|
signing_key:
|
66
67
|
specification_version: 4
|
67
68
|
summary: Controller action arguments parameterizer for Rails 3+ & Ruby 1.9+
|
@@ -72,5 +73,6 @@ test_files:
|
|
72
73
|
- spec/controllers/strong_parameters_spec.rb
|
73
74
|
- spec/fake_app.rb
|
74
75
|
- spec/kwargs_controllers.rb
|
76
|
+
- spec/mailers/action_mailer_spec.rb
|
75
77
|
- spec/params_handler/params_handler_spec.rb
|
76
78
|
- spec/spec_helper.rb
|