merge_params 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/merge_params/helpers.rb +24 -1
- data/lib/merge_params/version.rb +1 -1
- 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: 60f0644a975a59c156bcd0324be1f7a08e07d1bc
|
4
|
+
data.tar.gz: d2bdd9e4ab258fabb6025bfd49415014a94aa818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575ceab7b08f14f19aa7609709f64299effeaf21925d0dc4cedbdf4a776542cc237dfacea2983864c30e98aae752825444c8a37184e7feec3033158851fb6725
|
7
|
+
data.tar.gz: db13d502675945cad348f8ba5d0467c225a6abe513a8c89603ea47da9407bd2670ea2b2d81a5ada876603d5adf4da1ae5a1e39fe42f2adfb6310d925706eec17
|
data/lib/merge_params/helpers.rb
CHANGED
@@ -54,6 +54,29 @@ module MergeParams::Helpers
|
|
54
54
|
params_for_url_for.merge(new_params)
|
55
55
|
end
|
56
56
|
|
57
|
+
# Easily extract just certain param keys.
|
58
|
+
#
|
59
|
+
# Can't use permit().to_h — for example,
|
60
|
+
# params.permit(:page, :per_page, :filters).to_h
|
61
|
+
# or you'll get an error about whatever other unrelated keys happen to be set:
|
62
|
+
# found unpermitted parameters: :utf8, :commit, :company_id
|
63
|
+
#
|
64
|
+
# One good solution might be to have a permitted_params method defined with *all* of your
|
65
|
+
# permitted params for this controller, and then you could make other methods that fetch subsets
|
66
|
+
# of those params using slice. But if you don't want to do that, this slice_params helper is
|
67
|
+
# another good option.
|
68
|
+
#
|
69
|
+
# Other options include:
|
70
|
+
# - You *could* add those unrelated keys to always_permitted_parameters ... but that only works if
|
71
|
+
# all of them should be permitted *everywhere* — there are probably controller-specific params
|
72
|
+
# present that are permitted for this controller.
|
73
|
+
# - You could also change action_on_unpermitted_parameters — but unfortunately, there's no way to
|
74
|
+
# pass a temporary override value for that directly to permit, so the only option is to change it
|
75
|
+
# temporarily globally, which is inconvenient and not thread-safe.
|
76
|
+
def slice_params(*keys)
|
77
|
+
params_for_url_for.slice(*keys)
|
78
|
+
end
|
79
|
+
|
57
80
|
# Safely merges the given params with the params from the current request, then generates a route
|
58
81
|
# from the merged params.
|
59
82
|
def merge_url_for(new_params = {})
|
@@ -75,7 +98,7 @@ module MergeParams::Helpers
|
|
75
98
|
def add_params(params = {}, url = request.fullpath)
|
76
99
|
uri = URI(url)
|
77
100
|
params = parse_nested_query(uri.query || '').merge(params)
|
78
|
-
uri.query = Rack::Utils.build_nested_query(params)
|
101
|
+
uri.query = Rack::Utils.build_nested_query(params) if params.present?
|
79
102
|
uri.to_s
|
80
103
|
end
|
81
104
|
|
data/lib/merge_params/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merge_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rick
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.6.
|
138
|
+
rubygems_version: 2.6.14.3
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Safely merge params for use with url_for or for the query string
|