rails_conditional_params 0.1.0 → 0.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 +2 -0
- data/lib/rails_conditional_params.rb +19 -0
- data/lib/rails_conditional_params/patch.rb +1 -17
- data/lib/rails_conditional_params/version.rb +1 -1
- data/spec/params_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0147ea4dea489f5b3a34ca1dba8b955a1058d2ff
|
4
|
+
data.tar.gz: 06d56463e9de9be6b50ed8ac72dec291a01a4d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242e25d5664b5002f3e1af4569be93e43851f6c1a9472a39bce4794d1aa5e47d2ac7b43beeef162a72761fcd87d447eaf3a588334100da05bad62fc7f9450195
|
7
|
+
data.tar.gz: 2478d1b6affaf4e801fbe77fea341b745597fd4e5ed8ef48d5d5cbd55e7cee23e587ac2b6794ee7d5fad66648f1567eeede61ce4931681b373d90c806221d8fd
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@ Basically, it ensures that any hash key passed to `permit()` with `true` as
|
|
6
6
|
its value is made into a permitted key, while keys passed with `false` or `nil`
|
7
7
|
are ignored.
|
8
8
|
|
9
|
+
It is compatible with Rails 4.2 and later, including Rails 5.
|
10
|
+
|
9
11
|
## Installation
|
10
12
|
|
11
13
|
Add this line to your application's Gemfile:
|
@@ -5,4 +5,23 @@ require "rails_conditional_params/patch"
|
|
5
5
|
|
6
6
|
module RailsConditionalParams
|
7
7
|
ActionController::Parameters.include Patch
|
8
|
+
|
9
|
+
def RailsConditionalParams.restructure_filters!(filters)
|
10
|
+
filters.each do |filter|
|
11
|
+
if filter.is_a? Hash
|
12
|
+
filter.delete_if do |key, value|
|
13
|
+
case value
|
14
|
+
when TrueClass
|
15
|
+
filters << key
|
16
|
+
true
|
17
|
+
when FalseClass, NilClass
|
18
|
+
# do nothing
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
8
27
|
end
|
@@ -11,23 +11,7 @@ module RailsConditionalParams
|
|
11
11
|
# params.permit(:title, :body, published: admin?)
|
12
12
|
# # Result only includes published if admin? is true.
|
13
13
|
def permit_with_conditional_params(*filters)
|
14
|
-
|
15
|
-
if filter.is_a? Hash
|
16
|
-
filter.delete_if do |key, value|
|
17
|
-
case value
|
18
|
-
when TrueClass
|
19
|
-
filters << key
|
20
|
-
true
|
21
|
-
when FalseClass, NilClass
|
22
|
-
# do nothing
|
23
|
-
true
|
24
|
-
else
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
14
|
+
RailsConditionalParams.restructure_filters! filters
|
31
15
|
permit_without_conditional_params(*filters)
|
32
16
|
end
|
33
17
|
|
data/spec/params_spec.rb
CHANGED
@@ -7,14 +7,14 @@ describe ActionController::Parameters do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should work the same without conditionals" do
|
10
|
-
expect(@params.permit(:allowed)).to eq("allowed" => "allowed")
|
10
|
+
expect(@params.permit(:allowed).to_h).to eq("allowed" => "allowed")
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should include conditionals when conditionals are true" do
|
14
|
-
expect(@params.permit(:allowed, maybe: true)).to eq("allowed" => "allowed", "maybe" => "maybe")
|
14
|
+
expect(@params.permit(:allowed, maybe: true).to_h).to eq("allowed" => "allowed", "maybe" => "maybe")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should exclude conditionals when conditionals are false" do
|
18
|
-
expect(@params.permit(:allowed, maybe: false)).to eq("allowed" => "allowed")
|
18
|
+
expect(@params.permit(:allowed, maybe: false).to_h).to eq("allowed" => "allowed")
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_conditional_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Royal-Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.5.2
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Patches ActionController::Parameters to let you easily permit parameters
|