grape-path-helpers 2.1.0 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef633560ae5d3ff3ce265a852961fbe64f36363aabb3d454f29f081abc4e865b
4
- data.tar.gz: 8434f1082e0c1ffef30e2c2c53835939f2b9ae2b2354476139886838a5b83ef3
3
+ metadata.gz: 2ceaf5b98957d3b445254e411294acddf2c7cdf484ae5f6d190ccb3f1947c996
4
+ data.tar.gz: fcfd0e19ca6aeb2d5185af2528680c4f64a1d97749f9515481bebd330a6bed44
5
5
  SHA512:
6
- metadata.gz: 5f621e91cd80c07dcdfafa85836e9445f9c69fbea6995afcf850bff7b2715fa4b5753b534ba6dfc6eaf9594cd538da99ea47480b67cdb086830b35195c4ee9ad
7
- data.tar.gz: 80816e454a2866151cbfa21521bc6b3411e08893156e2d1d94b88d493bc7de04dae2b4929ebf8bd09de178a71d23873b4bad7def8adbefea7028aa31e11ad928
6
+ metadata.gz: 2e7dbe728e2998b3797a06028cff1c06914e189721355260da982266cf13b71d0e4ed476132fb0db5dc4f1c5ee6df20fb435f9d43af6c9f7135074fe57a69c54
7
+ data.tar.gz: 436b0ae0f6db17e8f25d39275542b58c28d524fccdc76d207f840cd95adb3d69054b935fdc4a7fe0cfd1393b6b32373ac7709d989bff78d504a8274c28e16b72
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.0
4
+
5
+ * [Support Grape 4.x](https://gitlab.com/gitlab-org/ruby/gems/grape-path-helpers/-/merge_requests/55)
6
+
3
7
  ## 2.1.0
4
8
 
5
9
  * [Support Grape 3.x](https://gitlab.com/gitlab-org/ruby/gems/grape-path-helpers/-/merge_requests/50)
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'grape', '~> 2.4.0'
7
+ gem 'grape', '~> 3.2'
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-path-helpers (2.1.0)
4
+ grape-path-helpers (2.2.0)
5
5
  activesupport
6
- grape (>= 2.0, < 4)
6
+ grape (>= 2.0, < 5)
7
7
  rake (> 12)
8
8
  ruby2_keywords (~> 0.0.2)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (8.1.3)
13
+ activesupport (8.1.4.1)
14
14
  base64
15
15
  bigdecimal
16
16
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -25,12 +25,15 @@ GEM
25
25
  uri (>= 0.13.1)
26
26
  ast (2.4.3)
27
27
  base64 (0.3.0)
28
- bigdecimal (4.1.2)
28
+ bigdecimal (4.1.3)
29
29
  coderay (1.1.3)
30
- concurrent-ruby (1.3.6)
31
- connection_pool (3.0.2)
30
+ concurrent-ruby (1.3.8)
31
+ connection_pool (3.0.3)
32
32
  diff-lcs (1.6.2)
33
33
  drb (2.2.3)
34
+ dry-configurable (1.4.0)
35
+ dry-core (~> 1.0)
36
+ zeitwerk (~> 2.6)
34
37
  dry-core (1.2.0)
35
38
  concurrent-ruby (~> 1.0)
36
39
  logger
@@ -48,26 +51,25 @@ GEM
48
51
  dry-inflector (~> 1.0)
49
52
  dry-logic (~> 1.4)
50
53
  zeitwerk (~> 2.6)
51
- grape (2.4.0)
52
- activesupport (>= 6.1)
54
+ grape (3.3.5)
55
+ activesupport (>= 7.2)
56
+ dry-configurable (>= 1.0)
53
57
  dry-types (>= 1.1)
54
- mustermann-grape (~> 1.1.0)
55
- rack (>= 2)
56
- zeitwerk
57
- i18n (1.14.8)
58
+ mustermann (>= 4.0)
59
+ rack (>= 2.2.4)
60
+ zeitwerk (>= 2.6)
61
+ i18n (1.15.2)
58
62
  concurrent-ruby (~> 1.0)
59
63
  io-console (0.8.2)
60
- json (2.19.5)
64
+ json (2.21.2)
61
65
  language_server-protocol (3.17.0.5)
62
66
  lint_roller (1.1.0)
63
67
  logger (1.7.0)
64
68
  method_source (1.1.0)
65
- minitest (6.0.6)
69
+ minitest (6.1.0)
66
70
  drb (~> 2.0)
67
- prism (~> 1.5)
71
+ prism (>= 1.5, < 3)
68
72
  mustermann (4.0.0)
69
- mustermann-grape (1.1.0)
70
- mustermann (>= 1.0.0)
71
73
  parallel (2.1.0)
72
74
  parser (3.3.11.1)
73
75
  ast (~> 2.4.1)
@@ -119,7 +121,7 @@ GEM
119
121
  unicode-display_width (3.2.0)
120
122
  unicode-emoji (~> 4.1)
121
123
  unicode-emoji (4.2.0)
122
- uri (1.1.1)
124
+ uri (1.1.2)
123
125
  zeitwerk (2.8.1)
124
126
 
125
127
  PLATFORMS
@@ -127,7 +129,7 @@ PLATFORMS
127
129
  ruby
128
130
 
129
131
  DEPENDENCIES
130
- grape (~> 2.4.0)
132
+ grape (~> 3.2)
131
133
  grape-path-helpers!
132
134
  pry (~> 0.11)
133
135
  rspec (~> 3.7)
data/Gemfile.next CHANGED
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  # `.next` mirrors the convention used in gitlab-org/gitlab: this Gemfile
6
- # tracks the version of Grape we're moving towards (3.x) while the root
7
- # `Gemfile` stays pinned to the version currently in production (2.4).
8
- gem 'grape', '~> 3.0'
6
+ # tracks the version of Grape we're moving towards (4.x) while the root
7
+ # `Gemfile` stays pinned to the version currently in production (3.x).
8
+ gem 'grape', '~> 4.0'
data/Gemfile.next.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-path-helpers (2.1.0)
4
+ grape-path-helpers (2.2.0)
5
5
  activesupport
6
- grape (>= 2.0, < 4)
6
+ grape (>= 2.0, < 5)
7
7
  rake (> 12)
8
8
  ruby2_keywords (~> 0.0.2)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (8.1.3)
13
+ activesupport (8.1.4.1)
14
14
  base64
15
15
  bigdecimal
16
16
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -25,10 +25,10 @@ GEM
25
25
  uri (>= 0.13.1)
26
26
  ast (2.4.3)
27
27
  base64 (0.3.0)
28
- bigdecimal (4.1.2)
28
+ bigdecimal (4.1.3)
29
29
  coderay (1.1.3)
30
- concurrent-ruby (1.3.6)
31
- connection_pool (3.0.2)
30
+ concurrent-ruby (1.3.8)
31
+ connection_pool (3.0.3)
32
32
  diff-lcs (1.6.2)
33
33
  drb (2.2.3)
34
34
  dry-configurable (1.4.0)
@@ -44,34 +44,32 @@ GEM
44
44
  concurrent-ruby (~> 1.0)
45
45
  dry-core (~> 1.1)
46
46
  zeitwerk (~> 2.6)
47
- dry-types (1.9.1)
47
+ dry-types (1.9.2)
48
48
  bigdecimal (>= 3.0)
49
49
  concurrent-ruby (~> 1.0)
50
50
  dry-core (~> 1.0)
51
51
  dry-inflector (~> 1.0)
52
52
  dry-logic (~> 1.4)
53
53
  zeitwerk (~> 2.6)
54
- grape (3.2.1)
54
+ grape (4.1.0)
55
55
  activesupport (>= 7.2)
56
- dry-configurable
56
+ dry-configurable (>= 1.0)
57
57
  dry-types (>= 1.1)
58
- mustermann-grape (~> 1.1.0)
59
- rack (>= 2)
60
- zeitwerk
61
- i18n (1.14.8)
58
+ mustermann (>= 4.0)
59
+ rack (>= 2.2.4)
60
+ zeitwerk (>= 2.6)
61
+ i18n (1.15.2)
62
62
  concurrent-ruby (~> 1.0)
63
63
  io-console (0.8.2)
64
- json (2.19.5)
64
+ json (2.21.2)
65
65
  language_server-protocol (3.17.0.5)
66
66
  lint_roller (1.1.0)
67
67
  logger (1.7.0)
68
68
  method_source (1.1.0)
69
- minitest (6.0.6)
69
+ minitest (6.1.0)
70
70
  drb (~> 2.0)
71
- prism (~> 1.5)
72
- mustermann (4.0.0)
73
- mustermann-grape (1.1.0)
74
- mustermann (>= 1.0.0)
71
+ prism (>= 1.5, < 3)
72
+ mustermann (4.0.1)
75
73
  parallel (2.1.0)
76
74
  parser (3.3.11.1)
77
75
  ast (~> 2.4.1)
@@ -82,7 +80,7 @@ GEM
82
80
  method_source (~> 1.0)
83
81
  reline (>= 0.6.0)
84
82
  racc (1.8.1)
85
- rack (3.2.6)
83
+ rack (3.2.8)
86
84
  rainbow (3.1.1)
87
85
  rake (13.4.2)
88
86
  regexp_parser (2.12.0)
@@ -123,15 +121,15 @@ GEM
123
121
  unicode-display_width (3.2.0)
124
122
  unicode-emoji (~> 4.1)
125
123
  unicode-emoji (4.2.0)
126
- uri (1.1.1)
127
- zeitwerk (2.8.1)
124
+ uri (1.1.2)
125
+ zeitwerk (2.8.3)
128
126
 
129
127
  PLATFORMS
130
128
  arm64-darwin-25
131
129
  ruby
132
130
 
133
131
  DEPENDENCIES
134
- grape (~> 3.0)
132
+ grape (~> 4.0)
135
133
  grape-path-helpers!
136
134
  pry (~> 0.11)
137
135
  rspec (~> 3.7)
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.required_ruby_version = '>= 3.2'
16
16
 
17
17
  gem.add_runtime_dependency 'activesupport'
18
- gem.add_runtime_dependency 'grape', '>= 2.0', '< 4'
18
+ gem.add_runtime_dependency 'grape', '>= 2.0', '< 5'
19
19
  gem.add_runtime_dependency 'rake', '> 12'
20
20
  gem.add_runtime_dependency 'ruby2_keywords', '~> 0.0.2'
21
21
 
@@ -25,9 +25,12 @@ module GrapePathHelpers
25
25
  @decorated_routes_by_helper_name = routes
26
26
  end
27
27
 
28
+ # Grape 4 no longer carries the computed version in the route options,
29
+ # so it has to be part of the route identity explicitly, otherwise the
30
+ # same path under two versions would collapse into one route
28
31
  def all_routes
29
32
  routes = descendants.flat_map { |d| d.endpoints.flat_map(&:routes) }
30
- routes.uniq { |r| r.options.merge(path: r.path) }
33
+ routes.uniq { |r| [r.path, r.version, r.options] }
31
34
  end
32
35
  end
33
36
  end
@@ -95,9 +95,16 @@ module GrapePathHelpers
95
95
  "#{sanitized_name}_path"
96
96
  end
97
97
 
98
+ # values the route supplies for its own dynamic segments, like the
99
+ # version of a path-versioned API. Grape 4 exposes the version through
100
+ # a reader only, earlier versions also carried it in the route options
101
+ def route_defaults
102
+ @route_defaults ||= route_options.to_h.merge(version: route_version)
103
+ end
104
+
98
105
  def segment_to_value(segment, opts = {})
99
106
  if dynamic_segment?(segment)
100
- options = route.options.merge(stringify_keys(opts))
107
+ options = route_defaults.merge(stringify_keys(opts))
101
108
  key = segment.slice(1..-1).to_sym
102
109
  options[key]
103
110
  else
@@ -140,7 +147,7 @@ module GrapePathHelpers
140
147
 
141
148
  def required_helper_segments
142
149
  segments_in_options = dynamic_path_segments.select do |segment|
143
- route.options[segment.to_sym]
150
+ route_defaults[segment.to_sym]
144
151
  end
145
152
  dynamic_path_segments - segments_in_options
146
153
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Gem version
4
4
  module GrapePathHelpers
5
- VERSION = '2.1.0'
5
+ VERSION = '2.2.0'
6
6
  end
@@ -13,9 +13,10 @@ describe GrapePathHelpers::AllRoutes do
13
13
  it 'does not include the same route twice' do
14
14
  mounting_api
15
15
 
16
- # A route is unique if no other route shares the same set of options
16
+ # A route is unique if no other route shares the same path, version
17
+ # and set of options
17
18
  all_route_options = Grape::API::Instance.all_routes.map do |r|
18
- r.instance_variable_get(:@options).merge(path: r.path)
19
+ [r.path, r.version, r.instance_variable_get(:@options)]
19
20
  end
20
21
 
21
22
  duplicates = all_route_options.select do |o|
@@ -26,6 +27,16 @@ describe GrapePathHelpers::AllRoutes do
26
27
  end
27
28
  end
28
29
 
30
+ context 'when two APIs share a path under different versions' do
31
+ it 'returns the route of each version' do
32
+ versions = Grape::API::Instance.all_routes.select do |r|
33
+ r.path == '/api/:version/ping(.json)'
34
+ end.map(&:version)
35
+
36
+ expect(versions).to include('v1', 'v2')
37
+ end
38
+ end
39
+
29
40
  context 'when there are multiple POST routes with the same namespace in the same API' do
30
41
  it 'returns all POST routes' do
31
42
  expected_routes = Spec::Support::MultiplePostsAPI.routes.map(&:path)
@@ -52,6 +52,12 @@ describe GrapePathHelpers::NamedRouteMatcher do
52
52
  end
53
53
  end
54
54
 
55
+ context 'when another API shares the path under another version' do
56
+ it 'returns the path of each version' do
57
+ expect(helper_class.api_v2_ping_path).to eq('/api/v2/ping.json')
58
+ end
59
+ end
60
+
55
61
  context 'when route requires dynamic segments but none are passed in' do
56
62
  it 'returns super method_missing' do
57
63
  expect(helper_class.api_v1_cats_owners_path)
data/spec/support/api.rb CHANGED
@@ -49,6 +49,17 @@ module Spec
49
49
  end
50
50
  end
51
51
 
52
+ # API sharing a path with the test API under another version
53
+ class APIWithAnotherVersion < Grape::API::Instance
54
+ version 'v2'
55
+ prefix 'api'
56
+ format 'json'
57
+
58
+ get 'ping' do
59
+ 'pong'
60
+ end
61
+ end
62
+
52
63
  # API with more than one version
53
64
  class APIWithMultipleVersions < Grape::API::Instance
54
65
  version %w[beta alpha v1]
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: 2.1.0
4
+ version: 2.2.0
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: 2026-08-05 00:00:00.000000000 Z
12
+ date: 2026-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '2.0'
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
- version: '4'
37
+ version: '5'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '2.0'
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '4'
47
+ version: '5'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
50
  requirement: !ruby/object:Gem::Requirement