grape-path-helpers 1.0.6 → 1.5.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
- SHA1:
3
- metadata.gz: e815c5ab96ef4eb2cc8485164b66d52fad17ef84
4
- data.tar.gz: ad85602cc19898c77ffe765c4af0806b10485cd9
2
+ SHA256:
3
+ metadata.gz: f0bb904ceffcf1cf4e877c5f97558f9d44883675269b20f6b8b76e74ba030fb0
4
+ data.tar.gz: ddf94c3bc25ef08377160f78298ae9905b6b83099cfaacec4e50202723582e5c
5
5
  SHA512:
6
- metadata.gz: 8357a7a8d21d72d1cfd5daa5962e44f0444e1f5d0682c257484d8c22508d4350cb839598fe65cf25f32a9429c32d0c4f603c513ff69fb7532c16165a384d58f2
7
- data.tar.gz: 4319294fe446969741d1badabca8c757184f9556aec29533b91f78f3ae13feefb84e2bbf600601281f318f5284a1f376008e9a0515ed44a9a27fc999b9c0ef13
6
+ metadata.gz: ded4e9c49e798b3127ca4169b269c09a68890c498d079d6bca2a9ca06532b0bacb2f09615b82f04646fc988a4bfcfa995623c9e93e5ec7a6e52e4df69698cf07
7
+ data.tar.gz: 93eaa299b50943cd6d8bcfd72f48f97da3d89ac557cabab44f6976297e275bb6fc2cf684ec6b9aa36fa8774980097c825a22978e19a86294a9944edac61b3559
@@ -1,17 +1,18 @@
1
- image: "ruby:2.4-alpine"
1
+ image: "ruby:2.7-alpine"
2
2
 
3
3
  cache:
4
4
  paths:
5
5
  - vendor/ruby
6
+ key: ruby-2.7
6
7
 
7
8
  before_script:
8
9
  - apk add --update git
9
10
  - gem install bundler
10
- - bundle install
11
+ - bundle install --path vendor/ruby
11
12
 
12
13
  rubocop:
13
14
  script:
14
- - rubocop
15
+ - bundle exec rubocop
15
16
 
16
17
  rspec:
17
18
  script:
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0
4
+
5
+ * [Relax rake dependency](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/27)
6
+
7
+ ## 1.4.0
8
+
9
+ * [Support using a base class other than Grape::API::Instance](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/23)
10
+
11
+ ## 1.3.0
12
+
13
+ * [Upgrade to Grape 1.3.1](https://gitlab.com/gitlab-org/grape-path-helpers/-/merge_requests/21)
14
+
15
+ ## 1.2.0
16
+
17
+ * [Add wildcard segments support](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/16)
18
+
19
+ ## 1.1.0
20
+
21
+ * [Relax dependency on ActiveSupport](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/12)
22
+
3
23
  ## 1.0.6
4
24
 
5
25
  * [Fix segments parsing for optional segments](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/10)
@@ -1,48 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-path-helpers (1.0.5)
5
- activesupport (>= 4, < 5.1)
6
- grape (~> 1.0)
7
- rake (~> 12)
4
+ grape-path-helpers (1.5.0)
5
+ activesupport
6
+ grape (~> 1.3)
7
+ rake (> 12)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (5.0.7)
12
+ activesupport (6.0.3.4)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.2, >= 2.2.2)
17
18
  ast (2.4.0)
18
- axiom-types (0.1.1)
19
- descendants_tracker (~> 0.0.4)
20
- ice_nine (~> 0.11.0)
21
- thread_safe (~> 0.3, >= 0.3.1)
22
- builder (3.2.3)
19
+ builder (3.2.4)
23
20
  coderay (1.1.2)
24
- coercible (1.0.0)
25
- descendants_tracker (~> 0.0.1)
26
- concurrent-ruby (1.0.5)
27
- descendants_tracker (0.0.4)
28
- thread_safe (~> 0.3, >= 0.3.1)
21
+ concurrent-ruby (1.1.7)
29
22
  diff-lcs (1.3)
30
- equalizer (0.0.11)
31
- grape (1.0.3)
23
+ dry-configurable (0.11.6)
24
+ concurrent-ruby (~> 1.0)
25
+ dry-core (~> 0.4, >= 0.4.7)
26
+ dry-equalizer (~> 0.2)
27
+ dry-container (0.7.2)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-configurable (~> 0.1, >= 0.1.3)
30
+ dry-core (0.4.9)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-equalizer (0.3.0)
33
+ dry-inflector (0.2.0)
34
+ dry-logic (1.0.8)
35
+ concurrent-ruby (~> 1.0)
36
+ dry-core (~> 0.2)
37
+ dry-equalizer (~> 0.2)
38
+ dry-types (1.4.0)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-container (~> 0.3)
41
+ dry-core (~> 0.4, >= 0.4.4)
42
+ dry-equalizer (~> 0.3)
43
+ dry-inflector (~> 0.1, >= 0.1.2)
44
+ dry-logic (~> 1.0, >= 1.0.2)
45
+ grape (1.5.0)
32
46
  activesupport
33
47
  builder
48
+ dry-types (>= 1.1)
34
49
  mustermann-grape (~> 1.0.0)
35
50
  rack (>= 1.3.0)
36
51
  rack-accept
37
- virtus (>= 1.0.0)
38
- i18n (1.0.1)
52
+ i18n (1.8.5)
39
53
  concurrent-ruby (~> 1.0)
40
- ice_nine (0.11.2)
41
54
  method_source (0.9.0)
42
- minitest (5.11.3)
43
- mustermann (1.0.2)
44
- mustermann-grape (1.0.0)
45
- mustermann (~> 1.0.0)
55
+ minitest (5.14.2)
56
+ mustermann (1.1.1)
57
+ ruby2_keywords (~> 0.0.1)
58
+ mustermann-grape (1.0.1)
59
+ mustermann (>= 1.0.0)
46
60
  parallel (1.12.1)
47
61
  parser (2.5.1.0)
48
62
  ast (~> 2.4.0)
@@ -50,11 +64,11 @@ GEM
50
64
  pry (0.11.3)
51
65
  coderay (~> 1.1.0)
52
66
  method_source (~> 0.9.0)
53
- rack (2.0.5)
67
+ rack (2.2.3)
54
68
  rack-accept (0.4.5)
55
69
  rack (>= 0.4)
56
70
  rainbow (3.0.0)
57
- rake (12.3.1)
71
+ rake (13.0.1)
58
72
  rspec (3.7.0)
59
73
  rspec-core (~> 3.7.0)
60
74
  rspec-expectations (~> 3.7.0)
@@ -76,15 +90,12 @@ GEM
76
90
  ruby-progressbar (~> 1.7)
77
91
  unicode-display_width (~> 1.0, >= 1.0.1)
78
92
  ruby-progressbar (1.9.0)
93
+ ruby2_keywords (0.0.2)
79
94
  thread_safe (0.3.6)
80
- tzinfo (1.2.5)
95
+ tzinfo (1.2.7)
81
96
  thread_safe (~> 0.1)
82
97
  unicode-display_width (1.3.3)
83
- virtus (1.0.5)
84
- axiom-types (~> 0.1)
85
- coercible (~> 1.0)
86
- descendants_tracker (~> 0.0, >= 0.0.3)
87
- equalizer (~> 0.0, >= 0.0.9)
98
+ zeitwerk (2.4.1)
88
99
 
89
100
  PLATFORMS
90
101
  ruby
@@ -96,4 +107,4 @@ DEPENDENCIES
96
107
  rubocop (~> 0.56)
97
108
 
98
109
  BUNDLED WITH
99
- 1.16.2
110
+ 2.1.4
@@ -1,6 +1,7 @@
1
1
  MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Harper Henn
3
+ Copyright (c) 2015,2016 Harper Henn
4
+ Copyright (c) 2018-2020 GitLab B.V.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # grape-path-helpers
2
2
 
3
- [![Build status](https://gitlab.com/gitlab-org/grape-path-helpers/badges/master/build.svg)](https://gitlab.com/gitlab-org/grape-path-helpers/commits/master)
3
+ [![Build status](https://gitlab.com/gitlab-org/grape-path-helpers/badges/master/pipeline.svg)](https://gitlab.com/gitlab-org/grape-path-helpers/commits/master)
4
4
 
5
5
  Provides named route helpers for Grape APIs, similar to [Rails' route helpers](http://edgeguides.rubyonrails.org/routing.html#path-and-url-helpers).
6
6
 
7
- **This is a fork and rename of [group-route-helpers](https://github.com/reprah/grape-route-helpers). It [includes some fixes](CHANGELOG.md) needed for GitLab.**
7
+ **This is a fork and rename of [grape-route-helpers](https://github.com/reprah/grape-route-helpers). It [includes some fixes](CHANGELOG.md) needed for GitLab.**
8
8
 
9
9
  ### Installation
10
10
 
@@ -76,7 +76,7 @@ You can use helper methods in your REPL session by including a module:
76
76
  Use the methods inside your Grape API actions. Given this example API:
77
77
 
78
78
  ```ruby
79
- class ExampleAPI < Grape::API
79
+ class ExampleAPI < Grape::API::Instance
80
80
  version 'v1'
81
81
  prefix 'api'
82
82
  format 'json'
@@ -127,7 +127,7 @@ api_v1_anything_path # => '/api/v1/*anything'
127
127
  If you want to assign a custom helper name to a route, pass the `:as` option when creating your route in your API:
128
128
 
129
129
  ```ruby
130
- class Base < Grape::API
130
+ class Base < Grape::API::Instance
131
131
  get 'ping', as: 'is_the_server_running'
132
132
  'pong'
133
133
  end
@@ -169,6 +169,14 @@ end
169
169
 
170
170
  6.) Create a new pull request
171
171
 
172
+ ### Releasing
173
+
174
+ 1. Update the [CHANGELOG](CHANGELOG.md).
175
+ 2. Update the version in [lib/grape-path-helpers/version.rb](lib/grape-path-helpers/version.rb).
176
+ 3. [Tag](https://gitlab.com/gitlab-org/grape-path-helpers/-/tags) the commit with the version number prefixed by 'v'.
177
+ 4. Run `gem build grape-path-helpers` locally.
178
+ 5. Run `gem push $new_file.gem` locally, where `$new_file` is the file generated by the step above.
179
+
172
180
  ### License
173
181
 
174
182
  See LICENSE
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'bundler/gem_tasks'
3
4
 
4
5
  Bundler.setup :default, :test, :development
5
6
 
@@ -11,9 +11,9 @@ Gem::Specification.new do |gem|
11
11
  gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
12
12
  gem.homepage = 'https://gitlab.com/gitlab-org/grape-path-helpers'
13
13
 
14
- gem.add_runtime_dependency 'activesupport', '>= 4', '< 5.1'
15
- gem.add_runtime_dependency 'grape', '~> 1.0'
16
- gem.add_runtime_dependency 'rake', '~> 12'
14
+ gem.add_runtime_dependency 'activesupport'
15
+ gem.add_runtime_dependency 'grape', '~> 1.3'
16
+ gem.add_runtime_dependency 'rake', '> 12'
17
17
 
18
18
  gem.add_development_dependency 'pry', '~> 0.11'
19
19
  gem.add_development_dependency 'rspec', '~> 3.7'
@@ -12,5 +12,5 @@ module GrapePathHelpers
12
12
  require 'grape-path-helpers/railtie' if defined?(Rails)
13
13
  end
14
14
 
15
- Grape::API.extend GrapePathHelpers::AllRoutes
15
+ Grape::API::Instance.extend GrapePathHelpers::AllRoutes
16
16
  Grape::Endpoint.send(:include, GrapePathHelpers::NamedRouteMatcher)
@@ -11,7 +11,7 @@ module GrapePathHelpers
11
11
  end
12
12
 
13
13
  def all_routes
14
- routes = subclasses.flat_map { |s| s.send(:prepare_routes) }
14
+ routes = descendants.flat_map { |s| s.send(:prepare_routes) }
15
15
  routes.uniq { |r| r.options.merge(path: r.path) }
16
16
  end
17
17
  end
@@ -4,6 +4,9 @@ module GrapePathHelpers
4
4
  attr_reader :route, :helper_names, :helper_arguments,
5
5
  :extension, :route_options
6
6
 
7
+ PATH_SEGMENTS_REGEXP = %r{\(/?\.:?\w+\)|/(?!\))|(?<=\))|\??\*}
8
+ PATH_SEGMENTS_WITH_WILDCARDS_REGEXP = %r{\(/?\.:?\w+\)|/(?!\))|(?<=\))|\?}
9
+
7
10
  def self.sanitize_method_name(string)
8
11
  string.gsub(/\W|^[0-9]/, '_')
9
12
  end
@@ -40,12 +43,12 @@ module GrapePathHelpers
40
43
 
41
44
  def define_path_helper(method_name, route_attributes)
42
45
  method_body = <<-RUBY
43
- def #{method_name}(attributes = {})
46
+ def #{method_name}(attributes = {}, include_wildcard_segments = false)
44
47
  attrs = #{route_attributes}.merge(attributes)
45
48
 
46
49
  query_params = attrs.delete(:params)
47
50
  content_type = attrs.delete(:format)
48
- path = '/' + path_segments_with_values(attrs).join('/')
51
+ path = '/' + path_segments_with_values(attrs, include_wildcard_segments).join('/')
49
52
 
50
53
  path + content_type + query_string(query_params)
51
54
  end
@@ -99,13 +102,19 @@ module GrapePathHelpers
99
102
  end
100
103
  end
101
104
 
102
- def path_segments_with_values(opts)
103
- segments = path_segments.map { |s| segment_to_value(s, opts) }
105
+ def path_segments_with_values(opts, include_wildcard_segments = false)
106
+ segments = path_segments(include_wildcard_segments).map do |s|
107
+ segment_to_value(s, opts)
108
+ end
104
109
  segments.reject(&:blank?)
105
110
  end
106
111
 
107
- def path_segments
108
- pattern = %r{\(/?\.:?\w+\)|/(?!\))|(?<=\))|\??\*}
112
+ def path_segments(include_wildcard_segments = false)
113
+ pattern = if include_wildcard_segments
114
+ PATH_SEGMENTS_WITH_WILDCARDS_REGEXP
115
+ else
116
+ PATH_SEGMENTS_REGEXP
117
+ end
109
118
  route_path.split(pattern).reject(&:blank?)
110
119
  end
111
120
 
@@ -117,7 +126,7 @@ module GrapePathHelpers
117
126
  end
118
127
 
119
128
  def dynamic_segment?(segment)
120
- segment.start_with?(':')
129
+ segment.start_with?(':', '*')
121
130
  end
122
131
 
123
132
  def optional_segment?(segment)
@@ -8,7 +8,7 @@ module GrapePathHelpers
8
8
 
9
9
  segments = arguments.first || {}
10
10
 
11
- route = Grape::API.decorated_routes.detect do |r|
11
+ route = Grape::API::Instance.decorated_routes.detect do |r|
12
12
  route_match?(r, method_id, segments)
13
13
  end
14
14
 
@@ -22,7 +22,7 @@ module GrapePathHelpers
22
22
  def respond_to_missing?(method_name, _include_private = false)
23
23
  return super unless method_name =~ /_path$/
24
24
 
25
- Grape::API.decorated_routes.detect do |route|
25
+ Grape::API::Instance.decorated_routes.detect do |route|
26
26
  return true if route.respond_to?(method_name)
27
27
  end
28
28
 
@@ -3,7 +3,7 @@ module GrapePathHelpers
3
3
  # and required arguments for every Grape::Route.
4
4
  class RouteDisplayer
5
5
  def route_attributes
6
- Grape::API.decorated_routes.map do |route|
6
+ Grape::API::Instance.decorated_routes.map do |route|
7
7
  {
8
8
  route_path: route.route_path,
9
9
  route_method: route.route_method,
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module GrapePathHelpers
3
- VERSION = '1.0.6'.freeze
3
+ VERSION = '1.5.0'.freeze
4
4
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # rubocop:disable Metrics/BlockLength
3
4
  describe GrapePathHelpers::AllRoutes do
4
- Grape::API.extend described_class
5
+ Grape::API::Instance.extend described_class
5
6
 
6
7
  describe '#all_routes' do
7
8
  context 'when API is mounted within another API' do
@@ -11,7 +12,7 @@ describe GrapePathHelpers::AllRoutes do
11
12
  mounting_api
12
13
 
13
14
  # A route is unique if no other route shares the same set of options
14
- all_route_options = Grape::API.all_routes.map do |r|
15
+ all_route_options = Grape::API::Instance.all_routes.map do |r|
15
16
  r.instance_variable_get(:@options).merge(path: r.path)
16
17
  end
17
18
 
@@ -28,10 +29,18 @@ describe GrapePathHelpers::AllRoutes do
28
29
  it 'returns all POST routes' do
29
30
  expected_routes = Spec::Support::MultiplePostsAPI.routes.map(&:path)
30
31
 
31
- all_routes = Grape::API.all_routes
32
+ all_routes = Grape::API::Instance.all_routes
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
@@ -19,7 +19,7 @@ describe GrapePathHelpers::DecoratedRoute do
19
19
  end
20
20
 
21
21
  let(:catch_all_route) do
22
- routes.detect { |route| route.route_path =~ /\*/ }
22
+ routes.detect { |route| route.route_path =~ /\*path/ }
23
23
  end
24
24
 
25
25
  let(:custom_route) do
@@ -34,6 +34,10 @@ describe GrapePathHelpers::DecoratedRoute do
34
34
  routes.detect { |route| route.route_path =~ /optional/ }
35
35
  end
36
36
 
37
+ let(:wildcard_route) do
38
+ routes.detect { |route| route.route_path =~ /\*owner_ids/ }
39
+ end
40
+
37
41
  describe '#sanitize_method_name' do
38
42
  it 'removes characters that are illegal in Ruby method names' do
39
43
  illegal_names = ['beta-1', 'name_with_+', 'name_with_(']
@@ -51,6 +55,53 @@ describe GrapePathHelpers::DecoratedRoute do
51
55
  end
52
56
  end
53
57
 
58
+ describe '#define_path_helper' do
59
+ context 'with only static segments' do
60
+ let(:route) { ping_route }
61
+
62
+ subject { route.api_v1_ping_path }
63
+
64
+ it { is_expected.to eq '/api/v1/ping.json' }
65
+ end
66
+
67
+ context 'with optional segments' do
68
+ let(:route) { optional_route }
69
+
70
+ subject { route.api_v1_cats______optional_path }
71
+
72
+ it { is_expected.to eq '/api/v1/cats/(-/)/optional.json' }
73
+ end
74
+
75
+ context 'with dynamic segments' do
76
+ let(:route) { show_route }
77
+
78
+ subject { route.api_v1_cats_path(id: 1) }
79
+
80
+ it { is_expected.to eq '/api/v1/cats/1.json' }
81
+ end
82
+
83
+ context 'with wildcard segments' do
84
+ let(:route) { wildcard_route }
85
+
86
+ context 'including them' do
87
+ subject do
88
+ route.api_v1_cats_owners_owner_ids_cats_path(
89
+ { owner_ids: 'foobar' },
90
+ true
91
+ )
92
+ end
93
+
94
+ it { is_expected.to eq '/api/v1/cats/owners/foobar/cats.json' }
95
+ end
96
+
97
+ context 'excluding them' do
98
+ subject { route.api_v1_cats_owners_owner_ids_cats_path }
99
+
100
+ it { is_expected.to eq '/api/v1/cats/owners/owner_ids/cats.json' }
101
+ end
102
+ end
103
+ end
104
+
54
105
  describe '#helper_names' do
55
106
  context 'when a route is given a custom helper name' do
56
107
  it 'uses the custom name instead of the dynamically generated one' do
@@ -119,7 +170,7 @@ describe GrapePathHelpers::DecoratedRoute do
119
170
 
120
171
  describe '#path_segments_with_values' do
121
172
  context 'when path has dynamic segments' do
122
- it 'replaces segments with corresponding values found in @options' do
173
+ it 'replaces segments with corresponding values found in options' do
123
174
  opts = { id: 1 }
124
175
  result = show_route.path_segments_with_values(opts)
125
176
  expect(result).to include(1)
@@ -133,6 +184,74 @@ describe GrapePathHelpers::DecoratedRoute do
133
184
  end
134
185
  end
135
186
  end
187
+
188
+ context 'when path has wildcard segments' do
189
+ context 'with regex excluding them' do
190
+ it "doesn't replaces wildcard segments" do
191
+ opts = { version: 4, id: 34, owner_ids: 'foobar' }
192
+
193
+ result = wildcard_route.path_segments_with_values(opts)
194
+ expect(result).to include(4)
195
+ expect(result).to include(34)
196
+ expect(result).to include('owner_ids')
197
+ expect(result).not_to include('foobar')
198
+ end
199
+
200
+ it "doesn't blank wildcard segments" do
201
+ opts = { version: 4, id: 34, owner_ids: '' }
202
+
203
+ result = wildcard_route.path_segments_with_values(opts)
204
+ expect(result).to include(4)
205
+ expect(result).to include(34)
206
+ expect(result).to include('owner_ids')
207
+ end
208
+ end
209
+
210
+ context 'with regex including them' do
211
+ context 'replaces segments' do
212
+ it 'with static text' do
213
+ opts = { version: 4, id: 34, owner_ids: 'foobar' }
214
+
215
+ result = wildcard_route.path_segments_with_values(opts, true)
216
+ expect(result).to include(4)
217
+ expect(result).to include(34)
218
+ expect(result).to include('foobar')
219
+ expect(result).not_to include('owner_ids')
220
+ end
221
+
222
+ it 'with additional segments' do
223
+ opts = { version: 4, id: 34, owner_ids: 'foo/bar/baz' }
224
+
225
+ result = wildcard_route.path_segments_with_values(opts, true)
226
+ expect(result).to include(4)
227
+ expect(result).to include(34)
228
+ expect(result).to include('foo/bar/baz')
229
+ expect(result).not_to include('owner_ids')
230
+ end
231
+ end
232
+
233
+ it 'blanks wildcard segments' do
234
+ opts = { version: 4, id: 34, owner_ids: '' }
235
+
236
+ result = wildcard_route.path_segments_with_values(opts, true)
237
+ expect(result).to include(4)
238
+ expect(result).to include(34)
239
+ expect(result).not_to include('owner_ids')
240
+ end
241
+
242
+ context 'when options contains string keys' do
243
+ it 'replaces segments' do
244
+ opts = { 'version' => 4, 'id' => 34, 'owner_ids' => 'foobar' }
245
+
246
+ result = wildcard_route.path_segments_with_values(opts, true)
247
+ expect(result).to include(4)
248
+ expect(result).to include(34)
249
+ expect(result).to include('foobar')
250
+ expect(result).not_to include('owner_ids')
251
+ end
252
+ end
253
+ end
254
+ end
136
255
  end
137
256
 
138
257
  describe '#path_helper_name' do
@@ -165,6 +284,13 @@ describe GrapePathHelpers::DecoratedRoute do
165
284
  expect(result).to eq('api_v1_path_path')
166
285
  end
167
286
  end
287
+
288
+ context 'when the path has a wildcard segment' do
289
+ it 'returns a name without the glob star' do
290
+ result = wildcard_route.path_helper_name
291
+ expect(result).to eq('api_v1_cats_owners_owner_ids_cats_path')
292
+ end
293
+ end
168
294
  end
169
295
 
170
296
  describe '#segment_to_value' do
@@ -5,7 +5,7 @@ describe GrapePathHelpers::NamedRouteMatcher do
5
5
  include described_class
6
6
 
7
7
  let(:routes) do
8
- Grape::API.decorated_routes
8
+ Grape::API::Instance.decorated_routes
9
9
  end
10
10
 
11
11
  let(:ping_route) do
@@ -44,13 +44,13 @@ describe GrapePathHelpers::NamedRouteMatcher do
44
44
 
45
45
  describe '#method_missing' do
46
46
  it 'returns super method_missing if the method does not end with path' do
47
- expect(Grape::API).not_to receive(:decorated_routes)
47
+ expect(Grape::API::Instance).not_to receive(:decorated_routes)
48
48
 
49
49
  helper_class.test_method
50
50
  end
51
51
 
52
52
  it 'search for the route if the method ends with path' do
53
- expect(Grape::API).to receive(:decorated_routes).and_call_original
53
+ expect(Grape::API::Instance).to receive(:decorated_routes).and_call_original # rubocop:disable Metrics/LineLength
54
54
 
55
55
  helper_class.test_method_path
56
56
  end
@@ -146,14 +146,14 @@ describe GrapePathHelpers::NamedRouteMatcher do
146
146
  end
147
147
 
148
148
  describe '#respond_to_missing?' do
149
- it 'returns super if the method doesb not end with path' do
150
- expect(Grape::API).not_to receive(:decorated_routes)
149
+ it 'returns super if the method does not end with path' do
150
+ expect(Grape::API::Instance).not_to receive(:decorated_routes) # rubocop:disable Metrics/LineLength
151
151
 
152
152
  expect(helper_class.send(:respond_to_missing?, :test)).to eq(false)
153
153
  end
154
154
 
155
155
  it 'search for the route if the method ends with path' do
156
- expect(Grape::API).to receive(:decorated_routes).and_call_original
156
+ expect(Grape::API::Instance).to receive(:decorated_routes).and_call_original # rubocop:disable Metrics/LineLength
157
157
 
158
158
  expect(helper_class.send(:respond_to_missing?, :test_path)).to eq(false)
159
159
  end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Support
3
3
  # Test API
4
- class API < Grape::API
4
+ class API < Grape::API::Instance
5
5
  version 'v1'
6
6
  prefix 'api'
7
7
  format 'json'
@@ -36,6 +36,10 @@ module Spec
36
36
  get ':id/owners/:owner_id' do
37
37
  'owner'
38
38
  end
39
+
40
+ get ':id/owners/*owner_ids/cats' do
41
+ %w[cats cats cats]
42
+ end
39
43
  end
40
44
 
41
45
  route :any, '*path' do
@@ -44,7 +48,7 @@ module Spec
44
48
  end
45
49
 
46
50
  # API with more than one version
47
- class APIWithMultipleVersions < Grape::API
51
+ class APIWithMultipleVersions < Grape::API::Instance
48
52
  version %w[beta alpha v1]
49
53
 
50
54
  get 'ping' do
@@ -53,13 +57,13 @@ module Spec
53
57
  end
54
58
 
55
59
  # API with another API mounted inside it
56
- class MountedAPI < Grape::API
60
+ class MountedAPI < Grape::API::Instance
57
61
  mount Spec::Support::API
58
62
  mount Spec::Support::APIWithMultipleVersions
59
63
  end
60
64
 
61
65
  # API with a version that would be illegal as a method name
62
- class APIWithIllegalVersion < Grape::API
66
+ class APIWithIllegalVersion < Grape::API::Instance
63
67
  version 'beta-1'
64
68
 
65
69
  get 'ping' do
@@ -68,7 +72,7 @@ module Spec
68
72
  end
69
73
 
70
74
  # API with multiple POST routes
71
- class MultiplePostsAPI < Grape::API
75
+ class MultiplePostsAPI < Grape::API::Instance
72
76
  resource :hamlet do
73
77
  post 'to_be' do
74
78
  end
@@ -77,5 +81,14 @@ module Spec
77
81
  end
78
82
  end
79
83
  end
84
+
85
+ class BaseAPI < Grape::API::Instance
86
+ end
87
+
88
+ class DerivedAPI < BaseAPI
89
+ get 'derived_ping' do
90
+ 'pong'
91
+ end
92
+ end
80
93
  end
81
94
  end
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.0.6
4
+ version: 1.5.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: 2018-07-12 00:00:00.000000000 Z
12
+ date: 2020-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,46 +17,40 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '5.1'
20
+ version: '0'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
- version: '4'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '5.1'
27
+ version: '0'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: grape
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
32
  - - "~>"
39
33
  - !ruby/object:Gem::Version
40
- version: '1.0'
34
+ version: '1.3'
41
35
  type: :runtime
42
36
  prerelease: false
43
37
  version_requirements: !ruby/object:Gem::Requirement
44
38
  requirements:
45
39
  - - "~>"
46
40
  - !ruby/object:Gem::Version
47
- version: '1.0'
41
+ version: '1.3'
48
42
  - !ruby/object:Gem::Dependency
49
43
  name: rake
50
44
  requirement: !ruby/object:Gem::Requirement
51
45
  requirements:
52
- - - "~>"
46
+ - - ">"
53
47
  - !ruby/object:Gem::Version
54
48
  version: '12'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
52
  requirements:
59
- - - "~>"
53
+ - - ">"
60
54
  - !ruby/object:Gem::Version
61
55
  version: '12'
62
56
  - !ruby/object:Gem::Dependency
@@ -152,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
146
  - !ruby/object:Gem::Version
153
147
  version: '0'
154
148
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.5.2
149
+ rubygems_version: 3.1.4
157
150
  signing_key:
158
151
  specification_version: 4
159
152
  summary: Route path helpers for Grape