grape-path-helpers 1.6.1 → 1.6.2
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/CHANGELOG.md +4 -0
- data/Gemfile.lock +20 -22
- data/lib/grape-path-helpers/decorated_route.rb +2 -2
- data/lib/grape-path-helpers/named_route_matcher.rb +9 -6
- data/lib/grape-path-helpers/version.rb +1 -1
- data/spec/grape_path_helpers/named_route_matcher_spec.rb +11 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8734d9daeae94b2a878f9fc18e9c178546e3228132df7ed03a0b3e1ab4de9a2c
|
4
|
+
data.tar.gz: 7151c3498b0957a40be8fdf9751aea18a62628c01379a5861116c5f855910c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fecfaaab23602b4cc8f50a4a9356e228d69909b36f799000bce239798e443f35cb3aa0d2367d9980a0e58c41dd4f5671c501dab08a6fb94bfffb5148652d200
|
7
|
+
data.tar.gz: a6c4dd8fb3cd7bb33a96687a94ac0e96733af8ecfe5096f781b32139c3518b96295763405086d05389f54adf66bf96bd4940352cf322c5135158f274f0420c11
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.6.2
|
4
|
+
|
5
|
+
* [Improve performance of route matching](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/33)
|
6
|
+
|
3
7
|
## 1.6.1
|
4
8
|
|
5
9
|
* [Use ruby2_keywords to fix 2.7 warning](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/31)
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-path-helpers (1.
|
4
|
+
grape-path-helpers (1.6.2)
|
5
5
|
activesupport
|
6
6
|
grape (~> 1.3)
|
7
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.1)
|
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
22
|
concurrent-ruby (1.1.7)
|
22
23
|
diff-lcs (1.3)
|
23
|
-
dry-configurable (0.
|
24
|
+
dry-configurable (0.12.0)
|
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
32
|
dry-equalizer (0.3.0)
|
33
33
|
dry-inflector (0.2.0)
|
34
|
-
dry-logic (1.0
|
34
|
+
dry-logic (1.1.0)
|
35
35
|
concurrent-ruby (~> 1.0)
|
36
|
-
dry-core (~> 0.
|
37
|
-
dry-equalizer (~> 0.2)
|
36
|
+
dry-core (~> 0.5, >= 0.5)
|
38
37
|
dry-types (1.4.0)
|
39
38
|
concurrent-ruby (~> 1.0)
|
40
39
|
dry-container (~> 0.3)
|
@@ -42,17 +41,17 @@ GEM
|
|
42
41
|
dry-equalizer (~> 0.3)
|
43
42
|
dry-inflector (~> 0.1, >= 0.1.2)
|
44
43
|
dry-logic (~> 1.0, >= 1.0.2)
|
45
|
-
grape (1.5.
|
44
|
+
grape (1.5.1)
|
46
45
|
activesupport
|
47
46
|
builder
|
48
47
|
dry-types (>= 1.1)
|
49
48
|
mustermann-grape (~> 1.0.0)
|
50
49
|
rack (>= 1.3.0)
|
51
50
|
rack-accept
|
52
|
-
i18n (1.8.
|
51
|
+
i18n (1.8.7)
|
53
52
|
concurrent-ruby (~> 1.0)
|
54
53
|
method_source (0.9.0)
|
55
|
-
minitest (5.14.
|
54
|
+
minitest (5.14.3)
|
56
55
|
mustermann (1.1.1)
|
57
56
|
ruby2_keywords (~> 0.0.1)
|
58
57
|
mustermann-grape (1.0.1)
|
@@ -68,7 +67,7 @@ GEM
|
|
68
67
|
rack-accept (0.4.5)
|
69
68
|
rack (>= 0.4)
|
70
69
|
rainbow (3.0.0)
|
71
|
-
rake (13.0.
|
70
|
+
rake (13.0.3)
|
72
71
|
rspec (3.7.0)
|
73
72
|
rspec-core (~> 3.7.0)
|
74
73
|
rspec-expectations (~> 3.7.0)
|
@@ -91,11 +90,10 @@ GEM
|
|
91
90
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
92
91
|
ruby-progressbar (1.9.0)
|
93
92
|
ruby2_keywords (0.0.2)
|
94
|
-
|
95
|
-
|
96
|
-
thread_safe (~> 0.1)
|
93
|
+
tzinfo (2.0.4)
|
94
|
+
concurrent-ruby (~> 1.0)
|
97
95
|
unicode-display_width (1.3.3)
|
98
|
-
zeitwerk (2.4.
|
96
|
+
zeitwerk (2.4.2)
|
99
97
|
|
100
98
|
PLATFORMS
|
101
99
|
ruby
|
@@ -107,4 +105,4 @@ DEPENDENCIES
|
|
107
105
|
rubocop (~> 0.56)
|
108
106
|
|
109
107
|
BUNDLED WITH
|
110
|
-
2.
|
108
|
+
2.2.3
|
@@ -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
|
|
@@ -8,8 +8,14 @@ module GrapePathHelpers
|
|
8
8
|
|
9
9
|
segments = args.first || {}
|
10
10
|
|
11
|
+
# rubocop:disable Metrics/LineLength
|
12
|
+
raise ArgumentError, 'Helper options must be a hash' unless segments.is_a?(Hash)
|
13
|
+
# rubocop:enable Metrics/LineLength
|
14
|
+
|
15
|
+
requested_segments = segments.keys.map(&:to_s)
|
16
|
+
|
11
17
|
route = Grape::API::Instance.decorated_routes.detect do |r|
|
12
|
-
route_match?(r, method_id,
|
18
|
+
route_match?(r, method_id, requested_segments)
|
13
19
|
end
|
14
20
|
|
15
21
|
if route
|
@@ -30,12 +36,9 @@ module GrapePathHelpers
|
|
30
36
|
super
|
31
37
|
end
|
32
38
|
|
33
|
-
def route_match?(route, method_name,
|
39
|
+
def route_match?(route, method_name, requested_segments)
|
34
40
|
return false unless route.respond_to?(method_name)
|
35
|
-
|
36
|
-
raise ArgumentError, 'Helper options must be a hash' unless segments.is_a?(Hash)
|
37
|
-
# rubocop:enable Metrics/LineLength
|
38
|
-
requested_segments = segments.keys.map(&:to_s)
|
41
|
+
|
39
42
|
route.uses_segments_in_path_helper?(requested_segments)
|
40
43
|
end
|
41
44
|
end
|
@@ -55,6 +55,14 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
55
55
|
|
56
56
|
helper_class.test_method_path
|
57
57
|
end
|
58
|
+
|
59
|
+
context 'when segments is not a hash' do
|
60
|
+
it 'raises an ArgumentError' do
|
61
|
+
expect do
|
62
|
+
helper_class.test_method_path(1234)
|
63
|
+
end.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
end
|
58
66
|
end
|
59
67
|
|
60
68
|
describe '#route_match?' do
|
@@ -63,14 +71,6 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
63
71
|
let(:method_name) { :api_v1_ping_path }
|
64
72
|
let(:segments) { {} }
|
65
73
|
|
66
|
-
context 'when segments is not a hash' do
|
67
|
-
it 'raises an ArgumentError' do
|
68
|
-
expect do
|
69
|
-
route_match?(route, method_name, 1234)
|
70
|
-
end.to raise_error(ArgumentError)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
74
|
it 'returns true' do
|
75
75
|
is_match = route_match?(route, method_name, segments)
|
76
76
|
expect(is_match).to eq(true)
|
@@ -106,7 +106,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
106
106
|
context 'when route requires the requested segments' do
|
107
107
|
let(:route) { show_route }
|
108
108
|
let(:method_name) { :api_v1_cats_path }
|
109
|
-
let(:segments) { { id
|
109
|
+
let(:segments) { { 'id' => 1 } }
|
110
110
|
|
111
111
|
it 'returns true' do
|
112
112
|
is_match = route_match?(route, method_name, segments)
|
@@ -115,7 +115,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
context 'when route does not require the requested segments' do
|
118
|
-
let(:segments) { { some_option
|
118
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
119
119
|
|
120
120
|
it 'returns false' do
|
121
121
|
is_match = route_match?(route, method_name, segments)
|
@@ -125,7 +125,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
context 'when segments contains unexpected options' do
|
128
|
-
let(:segments) { { some_option
|
128
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
129
129
|
|
130
130
|
it 'returns false' do
|
131
131
|
is_match = route_match?(route, method_name, segments)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-path-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Blessing
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|