grape-path-helpers 1.3.0 → 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/.gitlab-ci.yml +2 -1
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +23 -25
- data/Rakefile +1 -0
- data/grape-path-helpers.gemspec +2 -1
- data/lib/grape-path-helpers/all_routes.rb +1 -1
- data/lib/grape-path-helpers/decorated_route.rb +2 -2
- data/lib/grape-path-helpers/named_route_matcher.rb +13 -9
- data/lib/grape-path-helpers/version.rb +1 -1
- data/spec/grape_path_helpers/all_routes_spec.rb +9 -0
- data/spec/grape_path_helpers/named_route_matcher_spec.rb +15 -14
- data/spec/support/api.rb +9 -0
- 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: 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/.gitlab-ci.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
7
|
+
## 1.6.1
|
|
8
|
+
|
|
9
|
+
* [Use ruby2_keywords to fix 2.7 warning](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/31)
|
|
10
|
+
|
|
11
|
+
## 1.6.0
|
|
12
|
+
|
|
13
|
+
* [Extract kwargs to fix 2.7 warnings](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/29)
|
|
14
|
+
|
|
15
|
+
## 1.5.0
|
|
16
|
+
|
|
17
|
+
* [Relax rake dependency](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/27)
|
|
18
|
+
|
|
19
|
+
## 1.4.0
|
|
20
|
+
|
|
21
|
+
* [Support using a base class other than Grape::API::Instance](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/23)
|
|
22
|
+
|
|
3
23
|
## 1.3.0
|
|
4
24
|
|
|
5
25
|
* [Upgrade to Grape 1.3.1](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/21)
|
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
|
-
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.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
|
-
concurrent-ruby (1.1.
|
|
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.
|
|
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)
|
|
@@ -64,11 +63,11 @@ GEM
|
|
|
64
63
|
pry (0.11.3)
|
|
65
64
|
coderay (~> 1.1.0)
|
|
66
65
|
method_source (~> 0.9.0)
|
|
67
|
-
rack (2.2.
|
|
66
|
+
rack (2.2.3)
|
|
68
67
|
rack-accept (0.4.5)
|
|
69
68
|
rack (>= 0.4)
|
|
70
69
|
rainbow (3.0.0)
|
|
71
|
-
rake (
|
|
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.
|
|
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
|
-
|
|
108
|
+
2.2.3
|
data/Rakefile
CHANGED
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,28 @@ 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
|
+
# 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)
|
|
10
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
|
|
16
|
-
route.send(method_id, *
|
|
22
|
+
route.send(method_id, *args)
|
|
17
23
|
else
|
|
18
24
|
super
|
|
19
25
|
end
|
|
20
26
|
end
|
|
27
|
+
ruby2_keywords(:method_missing)
|
|
21
28
|
|
|
22
29
|
def respond_to_missing?(method_name, _include_private = false)
|
|
23
30
|
return super unless method_name =~ /_path$/
|
|
@@ -29,12 +36,9 @@ module GrapePathHelpers
|
|
|
29
36
|
super
|
|
30
37
|
end
|
|
31
38
|
|
|
32
|
-
def route_match?(route, method_name,
|
|
39
|
+
def route_match?(route, method_name, requested_segments)
|
|
33
40
|
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)
|
|
41
|
+
|
|
38
42
|
route.uses_segments_in_path_helper?(requested_segments)
|
|
39
43
|
end
|
|
40
44
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
|
3
4
|
describe GrapePathHelpers::AllRoutes do
|
|
4
5
|
Grape::API::Instance.extend described_class
|
|
5
6
|
|
|
@@ -32,6 +33,14 @@ describe GrapePathHelpers::AllRoutes do
|
|
|
32
33
|
expect(all_routes.map(&:path)).to include(*expected_routes)
|
|
33
34
|
end
|
|
34
35
|
end
|
|
36
|
+
|
|
37
|
+
context 'when an API is created via an intermediate class' do
|
|
38
|
+
it 'includes those routes on both Grape::API::Instance and the base class' do
|
|
39
|
+
expect(Spec::Support::BaseAPI.all_routes.map(&:origin)).to include('/derived_ping')
|
|
40
|
+
expect(Grape::API::Instance.all_routes.map(&:origin)).to include('/derived_ping')
|
|
41
|
+
end
|
|
42
|
+
end
|
|
35
43
|
# rubocop:enable Metrics/LineLength
|
|
36
44
|
end
|
|
37
45
|
end
|
|
46
|
+
# rubocop:enable Metrics/BlockLength
|
|
@@ -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,7 +46,8 @@ 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
|
it 'search for the route if the method ends with path' do
|
|
@@ -54,6 +55,14 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
54
55
|
|
|
55
56
|
helper_class.test_method_path
|
|
56
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
|
|
57
66
|
end
|
|
58
67
|
|
|
59
68
|
describe '#route_match?' do
|
|
@@ -62,14 +71,6 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
62
71
|
let(:method_name) { :api_v1_ping_path }
|
|
63
72
|
let(:segments) { {} }
|
|
64
73
|
|
|
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
74
|
it 'returns true' do
|
|
74
75
|
is_match = route_match?(route, method_name, segments)
|
|
75
76
|
expect(is_match).to eq(true)
|
|
@@ -105,7 +106,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
105
106
|
context 'when route requires the requested segments' do
|
|
106
107
|
let(:route) { show_route }
|
|
107
108
|
let(:method_name) { :api_v1_cats_path }
|
|
108
|
-
let(:segments) { { id
|
|
109
|
+
let(:segments) { { 'id' => 1 } }
|
|
109
110
|
|
|
110
111
|
it 'returns true' do
|
|
111
112
|
is_match = route_match?(route, method_name, segments)
|
|
@@ -114,7 +115,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
context 'when route does not require the requested segments' do
|
|
117
|
-
let(:segments) { { some_option
|
|
118
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
|
118
119
|
|
|
119
120
|
it 'returns false' do
|
|
120
121
|
is_match = route_match?(route, method_name, segments)
|
|
@@ -124,7 +125,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
|
124
125
|
end
|
|
125
126
|
|
|
126
127
|
context 'when segments contains unexpected options' do
|
|
127
|
-
let(:segments) { { some_option
|
|
128
|
+
let(:segments) { { 'some_option' => 'some value' } }
|
|
128
129
|
|
|
129
130
|
it 'returns false' do
|
|
130
131
|
is_match = route_match?(route, method_name, segments)
|
data/spec/support/api.rb
CHANGED
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.2
|
|
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-06 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: []
|