Skip to content

Commit c636750

Browse files
authored
Revert "Make forward_match an internal kwarg instead of a route option"
1 parent b9f6e8d commit c636750

10 files changed

Lines changed: 11 additions & 115 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#### Features
44

55
* [#2768](https://github.com/ruby-grape/grape/pull/2768): Remove Guard - [@ericproulx](https://github.com/ericproulx).
6-
* [#2774](https://github.com/ruby-grape/grape/pull/2774): Make `forward_match` an internal kwarg instead of a route option - [@ericproulx](https://github.com/ericproulx).
76
* Your contribution here.
87

98
#### Fixes

UPGRADING.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
Upgrading Grape
22
===============
33

4-
### Upgrading to >= 4.0.0
5-
6-
#### `forward_match` is no longer exposed on routes
7-
8-
`forward_match` is an internal, construction-time detail that decides how a route matches incoming paths (a prefix match for mounted Rack apps, the compiled pattern otherwise). It is now passed to `Grape::Router::Route` as a keyword argument and derived from the mounted app instead of being carried in the route's options.
9-
10-
As a result it is no longer readable through `route.options[:forward_match]` or the `route.forward_match` reader — both previously returned the flag. Nothing in Grape consumed either, so this only affects code that introspected routes directly; there is no replacement, as the value is now purely internal.
11-
124
### Upgrading to >= 3.3
135

146
#### Minimum required Ruby is now 3.3

lib/grape/dsl/routing.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def mount(mounts, *opts)
160160
path:,
161161
app:,
162162
route_options: { anchor: false },
163+
forward_match: !app.respond_to?(:inheritable_setting),
163164
for: self
164165
)
165166
end

lib/grape/endpoint.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ def to_routes
276276
default_route_options = prepare_default_route_attributes(route_options)
277277
complete_route_options = route_options.merge(default_route_options)
278278
path_settings = prepare_default_path_settings
279-
forward_match = config.app && !config.app.respond_to?(:inheritable_setting)
280279

281280
config.http_methods.flat_map do |method|
282281
config.path.map do |path|
@@ -290,7 +289,7 @@ def to_routes
290289
version: default_route_options[:version],
291290
requirements: default_route_options[:requirements]
292291
)
293-
Grape::Router::Route.new(self, method, pattern, complete_route_options, forward_match:)
292+
Grape::Router::Route.new(self, method, pattern, complete_route_options)
294293
end
295294
end
296295
end
@@ -302,7 +301,8 @@ def prepare_default_route_attributes(route_options)
302301
requirements: prepare_routes_requirements(route_options[:requirements]),
303302
prefix: inheritable_setting.namespace_inheritable[:root_prefix],
304303
anchor: route_options.fetch(:anchor, true),
305-
settings: inheritable_setting.route.except(:declared_params, :saved_validations)
304+
settings: inheritable_setting.route.except(:declared_params, :saved_validations),
305+
forward_match: config.forward_match
306306
}
307307
end
308308

lib/grape/endpoint/options.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class Endpoint
88
# stays a plain Hash for downstream gems (e.g. grape-swagger).
99
# +:method+ is renamed to +:http_methods+ on the value object to avoid
1010
# shadowing +Object#method+ via the generated Data accessor.
11-
Options = Data.define(:path, :http_methods, :for, :route_options, :app, :format) do
12-
def initialize(path:, method:, route_options: {}, app: nil, format: nil, **rest)
11+
Options = Data.define(:path, :http_methods, :for, :route_options, :app, :format, :forward_match) do
12+
def initialize(path:, method:, route_options: {}, app: nil, format: nil, forward_match: nil, **rest)
1313
path = Array(path)
1414
path << '/' if path.empty?
15-
super(path:, http_methods: Array(method), route_options:, app:, format:, **rest)
15+
super(path:, http_methods: Array(method), route_options:, app:, format:, forward_match:, **rest)
1616
end
1717
end
1818
end

lib/grape/router/base_route.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BaseRoute
1010
attr_reader :options, :pattern
1111

1212
def_delegators :@pattern, :path, :origin
13-
def_delegators :@options, :description, :version, :requirements, :prefix, :anchor, :settings, *Grape::Util::ApiDescription::DSL_METHODS
13+
def_delegators :@options, :description, :version, :requirements, :prefix, :anchor, :settings, :forward_match, *Grape::Util::ApiDescription::DSL_METHODS
1414

1515
def initialize(pattern, options = {})
1616
@pattern = pattern

lib/grape/router/route.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Route < BaseRoute
1212

1313
def_delegators :@app, :call
1414

15-
def initialize(endpoint, method, pattern, options, forward_match:)
15+
def initialize(endpoint, method, pattern, options)
1616
super(pattern, options)
1717
@app = endpoint
1818
@request_method = upcase_method(method)
19-
@match_function = forward_match ? FORWARD_MATCH_METHOD : NON_FORWARD_MATCH_METHOD
19+
@match_function = options[:forward_match] ? FORWARD_MATCH_METHOD : NON_FORWARD_MATCH_METHOD
2020
end
2121

2222
def convert_to_head_request!

spec/grape/api_spec.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,21 +3708,6 @@ def self.call(object, _env)
37083708
expect(last_response.body).to eq('sauce')
37093709
end
37103710

3711-
it 'does not forward unknown subpaths to a mounted API' do
3712-
subject.namespace :cool do
3713-
app = Class.new(Grape::API) # rubocop:disable RSpec/DescribedClass
3714-
app.get('/awesome') { 'sauce' }
3715-
mount app
3716-
end
3717-
3718-
get '/cool/awesome'
3719-
expect(last_response).to be_successful
3720-
get '/cool/awesome/subpath'
3721-
expect(last_response).to be_not_found
3722-
get '/cool/unknown'
3723-
expect(last_response).to be_not_found
3724-
end
3725-
37263711
it 'mounts on a nested path' do
37273712
app1 = Class.new(described_class)
37283713
app2 = Class.new(described_class)

spec/grape/endpoint_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ def memoized
10341034
path: '/path',
10351035
app: {},
10361036
route_options: { anchor: false },
1037+
forward_match: true,
10371038
for: Class.new
10381039
}
10391040
end

spec/grape/router/route_spec.rb

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)