grape-path-helpers 1.4.0 → 1.6.3
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/.gitlab-ci.yml +2 -1
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +25 -29
- data/grape-path-helpers.gemspec +2 -1
- data/lib/grape-path-helpers/decorated_route.rb +2 -2
- data/lib/grape-path-helpers/named_route_matcher.rb +11 -9
- data/lib/grape-path-helpers/version.rb +1 -1
- data/spec/grape_path_helpers/named_route_matcher_spec.rb +25 -25
- metadata +22 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bc6c862d4ba4b9cedabaafaf461382721dd87e45cc7796ff13d9a7c643d1d46
|
|
4
|
+
data.tar.gz: d1198670aad0447e4b50821a19e460daced596a51de2ddc0155fd6adea5146aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 729437ba35e3b8d4e2133dc96d11c9b5eca8a40965099acee11c7795f0514248bf7d45a824bc13cfceeb02e31fff0057f1a8ead11bc9e2f6d629af1b17910ed3
|
|
7
|
+
data.tar.gz: 520a330a0d892189dc2bd4862a717b41423f7c98794082592a961fdddbdee4342b1dbad0a94a9a4a98dbee2fa05c58bdc4c6ff398cddfbd74ad206622fb09fce
|
data/.gitlab-ci.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.3
|
|
4
|
+
|
|
5
|
+
* [Fix route matcher when method ends in path and arg isn't a Hash](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/35)
|
|
6
|
+
|
|
7
|
+
## 1.6.2
|
|
8
|
+
|
|
9
|
+
* [Improve performance of route matching](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/33)
|
|
10
|
+
|
|
11
|
+
## 1.6.1
|
|
12
|
+
|
|
13
|
+
* [Use ruby2_keywords to fix 2.7 warning](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/31)
|
|
14
|
+
|
|
15
|
+
## 1.6.0
|
|
16
|
+
|
|
17
|
+
* [Extract kwargs to fix 2.7 warnings](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/29)
|
|
18
|
+
|
|
19
|
+
## 1.5.0
|
|
20
|
+
|
|
21
|
+
* [Relax rake dependency](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/27)
|
|
22
|
+
|
|
3
23
|
## 1.4.0
|
|
4
24
|
|
|
5
25
|
* [Support using a base class other than Grape::API::Instance](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/23)
|
data/Gemfile.lock
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
grape-path-helpers (1.
|
|
4
|
+
grape-path-helpers (1.6.3)
|
|
5
5
|
activesupport
|
|
6
6
|
grape (~> 1.3)
|
|
7
|
-
rake (
|
|
7
|
+
rake (> 12)
|
|
8
|
+
ruby2_keywords (~> 0.0.2)
|
|
8
9
|
|
|
9
10
|
GEM
|
|
10
11
|
remote: https://rubygems.org/
|
|
11
12
|
specs:
|
|
12
|
-
activesupport (6.
|
|
13
|
+
activesupport (6.1.3.2)
|
|
13
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
-
i18n (>=
|
|
15
|
-
minitest (
|
|
16
|
-
tzinfo (~>
|
|
17
|
-
zeitwerk (~> 2.
|
|
15
|
+
i18n (>= 1.6, < 2)
|
|
16
|
+
minitest (>= 5.1)
|
|
17
|
+
tzinfo (~> 2.0)
|
|
18
|
+
zeitwerk (~> 2.3)
|
|
18
19
|
ast (2.4.0)
|
|
19
20
|
builder (3.2.4)
|
|
20
21
|
coderay (1.1.2)
|
|
21
|
-
concurrent-ruby (1.1.
|
|
22
|
+
concurrent-ruby (1.1.8)
|
|
22
23
|
diff-lcs (1.3)
|
|
23
|
-
dry-configurable (0.
|
|
24
|
+
dry-configurable (0.12.1)
|
|
24
25
|
concurrent-ruby (~> 1.0)
|
|
25
|
-
dry-core (~> 0.
|
|
26
|
-
dry-equalizer (~> 0.2)
|
|
26
|
+
dry-core (~> 0.5, >= 0.5.0)
|
|
27
27
|
dry-container (0.7.2)
|
|
28
28
|
concurrent-ruby (~> 1.0)
|
|
29
29
|
dry-configurable (~> 0.1, >= 0.1.3)
|
|
30
|
-
dry-core (0.
|
|
30
|
+
dry-core (0.5.0)
|
|
31
31
|
concurrent-ruby (~> 1.0)
|
|
32
|
-
dry-equalizer (0.3.0)
|
|
33
32
|
dry-inflector (0.2.0)
|
|
34
|
-
dry-logic (1.0
|
|
33
|
+
dry-logic (1.2.0)
|
|
35
34
|
concurrent-ruby (~> 1.0)
|
|
36
|
-
dry-core (~> 0.
|
|
37
|
-
|
|
38
|
-
dry-types (1.4.0)
|
|
35
|
+
dry-core (~> 0.5, >= 0.5)
|
|
36
|
+
dry-types (1.5.1)
|
|
39
37
|
concurrent-ruby (~> 1.0)
|
|
40
38
|
dry-container (~> 0.3)
|
|
41
|
-
dry-core (~> 0.
|
|
42
|
-
dry-equalizer (~> 0.3)
|
|
39
|
+
dry-core (~> 0.5, >= 0.5)
|
|
43
40
|
dry-inflector (~> 0.1, >= 0.1.2)
|
|
44
41
|
dry-logic (~> 1.0, >= 1.0.2)
|
|
45
|
-
grape (1.5.
|
|
42
|
+
grape (1.5.3)
|
|
46
43
|
activesupport
|
|
47
44
|
builder
|
|
48
45
|
dry-types (>= 1.1)
|
|
49
46
|
mustermann-grape (~> 1.0.0)
|
|
50
47
|
rack (>= 1.3.0)
|
|
51
48
|
rack-accept
|
|
52
|
-
i18n (1.8.
|
|
49
|
+
i18n (1.8.10)
|
|
53
50
|
concurrent-ruby (~> 1.0)
|
|
54
51
|
method_source (0.9.0)
|
|
55
|
-
minitest (5.14.
|
|
52
|
+
minitest (5.14.4)
|
|
56
53
|
mustermann (1.1.1)
|
|
57
54
|
ruby2_keywords (~> 0.0.1)
|
|
58
55
|
mustermann-grape (1.0.1)
|
|
@@ -68,7 +65,7 @@ GEM
|
|
|
68
65
|
rack-accept (0.4.5)
|
|
69
66
|
rack (>= 0.4)
|
|
70
67
|
rainbow (3.0.0)
|
|
71
|
-
rake (
|
|
68
|
+
rake (13.0.3)
|
|
72
69
|
rspec (3.7.0)
|
|
73
70
|
rspec-core (~> 3.7.0)
|
|
74
71
|
rspec-expectations (~> 3.7.0)
|
|
@@ -90,12 +87,11 @@ GEM
|
|
|
90
87
|
ruby-progressbar (~> 1.7)
|
|
91
88
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
92
89
|
ruby-progressbar (1.9.0)
|
|
93
|
-
ruby2_keywords (0.0.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
thread_safe (~> 0.1)
|
|
90
|
+
ruby2_keywords (0.0.4)
|
|
91
|
+
tzinfo (2.0.4)
|
|
92
|
+
concurrent-ruby (~> 1.0)
|
|
97
93
|
unicode-display_width (1.3.3)
|
|
98
|
-
zeitwerk (2.4.
|
|
94
|
+
zeitwerk (2.4.2)
|
|
99
95
|
|
|
100
96
|
PLATFORMS
|
|
101
97
|
ruby
|
|
@@ -107,4 +103,4 @@ DEPENDENCIES
|
|
|
107
103
|
rubocop (~> 0.56)
|
|
108
104
|
|
|
109
105
|
BUNDLED WITH
|
|
110
|
-
|
|
106
|
+
2.2.3
|
data/grape-path-helpers.gemspec
CHANGED
|
@@ -13,7 +13,8 @@ Gem::Specification.new do |gem|
|
|
|
13
13
|
|
|
14
14
|
gem.add_runtime_dependency 'activesupport'
|
|
15
15
|
gem.add_runtime_dependency 'grape', '~> 1.3'
|
|
16
|
-
gem.add_runtime_dependency 'rake', '
|
|
16
|
+
gem.add_runtime_dependency 'rake', '> 12'
|
|
17
|
+
gem.add_runtime_dependency 'ruby2_keywords', '~> 0.0.2'
|
|
17
18
|
|
|
18
19
|
gem.add_development_dependency 'pry', '~> 0.11'
|
|
19
20
|
gem.add_development_dependency 'rspec', '~> 3.7'
|
|
@@ -147,10 +147,10 @@ module GrapePathHelpers
|
|
|
147
147
|
def uses_segments_in_path_helper?(segments)
|
|
148
148
|
segments = segments.reject { |x| special_keys.include?(x) }
|
|
149
149
|
|
|
150
|
-
if
|
|
150
|
+
if helper_arguments.empty? && segments.any?
|
|
151
151
|
false
|
|
152
152
|
else
|
|
153
|
-
|
|
153
|
+
helper_arguments.all? { |x| segments.include?(x) }
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
156
|
|
|
@@ -3,21 +3,26 @@ module GrapePathHelpers
|
|
|
3
3
|
# to unknown methods will look for a route with a matching
|
|
4
4
|
# helper function name
|
|
5
5
|
module NamedRouteMatcher
|
|
6
|
-
def method_missing(method_id, *
|
|
6
|
+
def method_missing(method_id, *args)
|
|
7
7
|
return super unless method_id.to_s =~ /_path$/
|
|
8
8
|
|
|
9
|
-
segments =
|
|
9
|
+
segments = args.first || {}
|
|
10
|
+
|
|
11
|
+
return super unless segments.is_a?(Hash)
|
|
12
|
+
|
|
13
|
+
requested_segments = segments.keys.map(&:to_s)
|
|
10
14
|
|
|
11
15
|
route = Grape::API::Instance.decorated_routes.detect do |r|
|
|
12
|
-
route_match?(r, method_id,
|
|
16
|
+
route_match?(r, method_id, requested_segments)
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
if route
|
|
16
|
-
route.send(method_id, *
|
|
20
|
+
route.send(method_id, *args)
|
|
17
21
|
else
|
|
18
22
|
super
|
|
19
23
|
end
|
|
20
24
|
end
|
|
25
|
+
ruby2_keywords(:method_missing)
|
|
21
26
|
|
|
22
27
|
def respond_to_missing?(method_name, _include_private = false)
|
|
23
28
|
return super unless method_name =~ /_path$/
|
|
@@ -29,12 +34,9 @@ module GrapePathHelpers
|
|
|
29
34
|
super
|
|
30
35
|
end
|
|
31
36
|
|
|
32
|
-
def route_match?(route, method_name,
|
|
37
|
+
def route_match?(route, method_name, requested_segments)
|
|
33
38
|
return false unless route.respond_to?(method_name)
|
|
34
|
-
|
|
35
|
-
raise ArgumentError, 'Helper options must be a hash' unless segments.is_a?(Hash)
|
|
36
|
-
# rubocop:enable Metrics/LineLength
|
|
37
|
-
requested_segments = segments.keys.map(&:to_s)
|
|
39
|
+
|
|
38
40
|
route.uses_segments_in_path_helper?(requested_segments)
|
|
39
41
|
end
|
|
40
42
|
end
|
|
@@ -30,8 +30,8 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
30
30
|
fake_class = Class.new do
|
|
31
31
|
prepend GrapePathHelpers::NamedRouteMatcher
|
|
32
32
|
|
|
33
|
-
def method_missing(
|
|
34
|
-
|
|
33
|
+
def method_missing(method_id, *args, **kwargs)
|
|
34
|
+
[method_id, args, kwargs] || super
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def respond_to_missing?(_method_name, _include_private = false)
|
|
@@ -46,13 +46,29 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
46
46
|
it 'returns super method_missing if the method does not end with path' do
|
|
47
47
|
expect(Grape::API::Instance).not_to receive(:decorated_routes)
|
|
48
48
|
|
|
49
|
-
helper_class.test_method
|
|
49
|
+
expect(helper_class.test_method(:arg1, kwarg1: :kwarg1))
|
|
50
|
+
.to eq([:test_method, [:arg1], { kwarg1: :kwarg1 }])
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
context 'when method ends with path' do
|
|
54
|
+
it 'returns super method_missing if first arg is not a hash' do
|
|
55
|
+
expect(Grape::API::Instance).not_to receive(:decorated_routes)
|
|
56
|
+
|
|
57
|
+
expect(helper_class.test_method_path(:arg1, kwarg1: :kwarg1))
|
|
58
|
+
.to eq([:test_method_path, [:arg1], { kwarg1: :kwarg1 }])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'search for the route if there are no args' do
|
|
62
|
+
expect(Grape::API::Instance).to receive(:decorated_routes).and_call_original # rubocop:disable Metrics/LineLength
|
|
63
|
+
|
|
64
|
+
helper_class.test_method_path
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'search for the route if the first arg is a hash' do
|
|
68
|
+
expect(Grape::API::Instance).to receive(:decorated_routes).and_call_original # rubocop:disable Metrics/LineLength
|
|
54
69
|
|
|
55
|
-
|
|
70
|
+
helper_class.test_method_path(id: 5)
|
|
71
|
+
end
|
|
56
72
|
end
|
|
57
73
|
end
|
|
58
74
|
|
|
@@ -62,14 +78,6 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
62
78
|
let(:method_name) { :api_v1_ping_path }
|
|
63
79
|
let(:segments) { {} }
|
|
64
80
|
|
|
65
|
-
context 'when segments is not a hash' do
|
|
66
|
-
it 'raises an ArgumentError' do
|
|
67
|
-
expect do
|
|
68
|
-
route_match?(route, method_name, 1234)
|
|
69
|
-
end.to raise_error(ArgumentError)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
81
|
it 'returns true' do
|
|
74
82
|
is_match = route_match?(route, method_name, segments)
|
|
75
83
|
expect(is_match).to eq(true)
|
|
@@ -105,7 +113,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
105
113
|
context 'when route requires the requested segments' do
|
|
106
114
|
let(:route) { show_route }
|
|
107
115
|
let(:method_name) { :api_v1_cats_path }
|
|
108
|
-
let(:segments) { { id
|
|
116
|
+
let(:segments) { { 'id' => 1 } }
|
|
109
117
|
|
|
110
118
|
it 'returns true' do
|
|
111
119
|
is_match = route_match?(route, method_name, segments)
|
|
@@ -114,7 +122,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
114
122
|
end
|
|
115
123
|
|
|
116
124
|
context 'when route does not require the requested segments' do
|
|
117
|
-
let(:segments) { { some_option
|
|
125
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
|
118
126
|
|
|
119
127
|
it 'returns false' do
|
|
120
128
|
is_match = route_match?(route, method_name, segments)
|
|
@@ -124,7 +132,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
124
132
|
end
|
|
125
133
|
|
|
126
134
|
context 'when segments contains unexpected options' do
|
|
127
|
-
let(:segments) { { some_option
|
|
135
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
|
128
136
|
|
|
129
137
|
it 'returns false' do
|
|
130
138
|
is_match = route_match?(route, method_name, segments)
|
|
@@ -189,14 +197,6 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
189
197
|
path = api_v1_ping_path
|
|
190
198
|
expect(path).to eq('/api/v1/ping.json')
|
|
191
199
|
end
|
|
192
|
-
|
|
193
|
-
context 'when argument to the helper is not a hash' do
|
|
194
|
-
it 'raises an ArgumentError' do
|
|
195
|
-
expect do
|
|
196
|
-
api_v1_ping_path(1234)
|
|
197
|
-
end.to raise_error(ArgumentError)
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
context 'when method name does not match a Grape::Route path helper name' do
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape-path-helpers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Drew Blessing
|
|
8
8
|
- Harper Henn
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -43,16 +43,30 @@ dependencies:
|
|
|
43
43
|
name: rake
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
|
-
- - "
|
|
46
|
+
- - ">"
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
48
|
version: '12'
|
|
49
49
|
type: :runtime
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
|
-
- - "
|
|
53
|
+
- - ">"
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '12'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: ruby2_keywords
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - "~>"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 0.0.2
|
|
63
|
+
type: :runtime
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - "~>"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 0.0.2
|
|
56
70
|
- !ruby/object:Gem::Dependency
|
|
57
71
|
name: pry
|
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -131,7 +145,7 @@ homepage: https://gitlab.com/gitlab-org/grape-path-helpers
|
|
|
131
145
|
licenses:
|
|
132
146
|
- MIT
|
|
133
147
|
metadata: {}
|
|
134
|
-
post_install_message:
|
|
148
|
+
post_install_message:
|
|
135
149
|
rdoc_options: []
|
|
136
150
|
require_paths:
|
|
137
151
|
- lib
|
|
@@ -146,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
146
160
|
- !ruby/object:Gem::Version
|
|
147
161
|
version: '0'
|
|
148
162
|
requirements: []
|
|
149
|
-
rubygems_version: 3.
|
|
150
|
-
signing_key:
|
|
163
|
+
rubygems_version: 3.2.3
|
|
164
|
+
signing_key:
|
|
151
165
|
specification_version: 4
|
|
152
166
|
summary: Route path helpers for Grape
|
|
153
167
|
test_files: []
|