merge_params 0.2.0 → 0.3.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 +5 -5
- data/Changelog.md +32 -0
- data/Readme.md +2 -0
- data/lib/merge_params/helpers.rb +10 -1
- data/lib/merge_params/version.rb +1 -1
- data/merge_params.gemspec +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d02292b14bbd8378da9306edaaf9ba131f54bf7a638ce247c96db14f10ef7e80
|
4
|
+
data.tar.gz: f86ffa29a81b4d8d427f99757f18ee4b505727830c7fb8b8e3459bd8fe4e3d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f14c18536515ec20bc11ab826acb0eabf8b417ee485a844eb3cb9fbf9e0d7ee24428e146f2f42ca79f10281cb68d12c1d0faca6159869634c65e3b9292827cac
|
7
|
+
data.tar.gz: e4c02db3a74fdb11ecc5b2ff4aa8a0ad65e0c2615af1c6338a6df4afc67e968391e1aa5a7f76b37c2f90f2b5f3e03e5aef8abe82ab8a005a53cbdea2acc0169f
|
data/Changelog.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the
|
4
|
+
recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
5
|
+
|
6
|
+
## (Unreleased)
|
7
|
+
|
8
|
+
|
9
|
+
## 0.3.0 (2019-01-24)
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Fix `merge_url_for` to not try to add a param as a query param if it's been recognized as a route
|
13
|
+
param (part of the route path). We don't want the same param to be passed both via the route path
|
14
|
+
*and* the query string.
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- `merge_url_for`: Allow keys that are currently in `query_params` to be deleted by setting their
|
18
|
+
value to `nil`.
|
19
|
+
|
20
|
+
|
21
|
+
## 0.2.0 (2018-12-05)
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
- Fix `add_params` to not inadvertently add a '?' to the end of the URI if there are no params to add
|
25
|
+
|
26
|
+
### Added
|
27
|
+
- Add `slice_params` helper
|
28
|
+
|
29
|
+
|
30
|
+
## 0.1.0 (2018-11-16)
|
31
|
+
|
32
|
+
Initial release
|
data/Readme.md
CHANGED
data/lib/merge_params/helpers.rb
CHANGED
@@ -79,13 +79,22 @@ module MergeParams::Helpers
|
|
79
79
|
|
80
80
|
# Safely merges the given params with the params from the current request, then generates a route
|
81
81
|
# from the merged params.
|
82
|
+
# You can remove a key by passing nil as the value, for example {key: nil}.
|
82
83
|
def merge_url_for(new_params = {})
|
83
84
|
url = url_for(merge_params(new_params))
|
84
85
|
|
85
86
|
# Now pass along in the *query string* any params that we couldn't pass to url_for because they
|
86
87
|
# were reserved options.
|
87
88
|
query_params_already_added = parse_nested_query(URI(url).query || '')
|
88
|
-
|
89
|
+
# Some params from new_params (like company_id) that we pass in may be recognized by a route and
|
90
|
+
# therefore no longer be query params. We use recognize_path to find those params that ended up
|
91
|
+
# as route params instead of query_params but are nonetheless aready added to the url.
|
92
|
+
params_already_added = Rails.application.routes.recognize_path(url).merge(query_params_already_added)
|
93
|
+
keys_already_added = params_already_added.keys
|
94
|
+
# Allow keys that are currently in query_params to be deleted by setting their value to nil in
|
95
|
+
# new_params.
|
96
|
+
keys_to_delete = new_params.select {|k,v| v.nil?}.keys
|
97
|
+
query_params_to_add = query_params.except(*keys_already_added + keys_to_delete)
|
89
98
|
add_params(query_params_to_add, url)
|
90
99
|
end
|
91
100
|
|
data/lib/merge_params/version.rb
CHANGED
data/merge_params.gemspec
CHANGED
@@ -11,11 +11,11 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{Safely merge params for use with url_for or for the query string}
|
13
13
|
spec.description = spec.summary
|
14
|
-
spec.homepage = "
|
14
|
+
spec.homepage = "https://github.com/TylerRick/merge_params"
|
15
15
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
-
spec.metadata["changelog_uri"] = "
|
18
|
+
spec.metadata["changelog_uri"] = "#{spec.metadata["source_code_uri"]}/blob/master/Changelog.md"
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
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.3.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:
|
11
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- ".gitignore"
|
103
103
|
- ".rspec"
|
104
104
|
- ".travis.yml"
|
105
|
+
- Changelog.md
|
105
106
|
- Gemfile
|
106
107
|
- License
|
107
108
|
- Rakefile
|
@@ -112,13 +113,13 @@ files:
|
|
112
113
|
- lib/merge_params/helpers.rb
|
113
114
|
- lib/merge_params/version.rb
|
114
115
|
- merge_params.gemspec
|
115
|
-
homepage:
|
116
|
+
homepage: https://github.com/TylerRick/merge_params
|
116
117
|
licenses:
|
117
118
|
- MIT
|
118
119
|
metadata:
|
119
|
-
homepage_uri:
|
120
|
-
source_code_uri:
|
121
|
-
changelog_uri:
|
120
|
+
homepage_uri: https://github.com/TylerRick/merge_params
|
121
|
+
source_code_uri: https://github.com/TylerRick/merge_params
|
122
|
+
changelog_uri: https://github.com/TylerRick/merge_params/blob/master/Changelog.md
|
122
123
|
post_install_message:
|
123
124
|
rdoc_options: []
|
124
125
|
require_paths:
|
@@ -134,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
|
138
|
-
rubygems_version: 2.6.14.3
|
138
|
+
rubygems_version: 3.0.1
|
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
|