Skip to content

Commit 3f01d03

Browse files
authored
method missing to_ary (#2370)
* Add to_ary nil * Add changelog * Remove method_missing and warning * Update CHANGELOG.md * Add upgrading notes Replace route_params by params * Update README.md
1 parent 76cae59 commit 3f01d03

File tree

5 files changed

+13
-42
lines changed

5 files changed

+13
-42
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#### Fixes
99

10+
* [#2370](https://github.com/ruby-grape/grape/pull/2370): Remove route_xyz method_missing deprecation - [@ericproulx](https://github.com/ericproulx).
1011
* [#2372](https://github.com/ruby-grape/grape/pull/2372): Fix `declared` method for hash params with overlapping names - [@jcagarcia](https://github.com/jcagarcia).
1112
* [#2373](https://github.com/ruby-grape/grape/pull/2373): Fix markdown files for following 1-line format - [@jcagarcia](https://github.com/jcagarcia).
1213
* Your contribution here.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3352,7 +3352,7 @@ You can access the controller params, headers, and helpers through the context w
33523352

33533353
Grape routes can be reflected at runtime. This can notably be useful for generating documentation.
33543354

3355-
Grape exposes arrays of API versions and compiled routes. Each route contains a `route_prefix`, `route_version`, `route_namespace`, `route_method`, `route_path` and `route_params`. You can add custom route settings to the route metadata with `route_setting`.
3355+
Grape exposes arrays of API versions and compiled routes. Each route contains a `prefix`, `version`, `namespace`, `method` and `params`. You can add custom route settings to the route metadata with `route_setting`.
33563356

33573357
```ruby
33583358
class TwitterAPI < Grape::API
@@ -3375,7 +3375,7 @@ TwitterAPI::routes[0].description # => 'Includes custom settings.'
33753375
TwitterAPI::routes[0].settings[:custom] # => { key: 'value' }
33763376
```
33773377

3378-
Note that `Route#route_xyz` methods have been deprecated since 0.15.0.
3378+
Note that `Route#route_xyz` methods have been deprecated since 0.15.0 and removed since 2.0.1.
33793379

33803380
Please use `Route#xyz` instead.
33813381

@@ -3395,7 +3395,7 @@ class MyAPI < Grape::API
33953395
requires :id, type: Integer, desc: 'Identity.'
33963396
end
33973397
get 'params/:id' do
3398-
route.route_params[params[:id]] # yields the parameter description
3398+
route.params[params[:id]] # yields the parameter description
33993399
end
34003400
end
34013401
```

UPGRADING.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Upgrading Grape
22
===============
33

4+
### Upgrading to >= 2.0.1
5+
6+
#### Grape::Router::Route.route_xxx methods have been removed
7+
8+
- `route_method` is accessible through `request_method`
9+
- `route_path` is accessible through `path`
10+
- Any other `route_xyz` are accessible through `options[xyz]`
11+
412
### Upgrading to >= 2.0.0
513

614
#### Headers

lib/grape/router/route.rb

-37
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
require 'grape/router/pattern'
44
require 'grape/router/attribute_translator'
55
require 'forwardable'
6-
require 'pathname'
76

87
module Grape
98
class Router
109
class Route
11-
ROUTE_ATTRIBUTE_REGEXP = /route_([_a-zA-Z]\w*)/.freeze
12-
SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/.freeze
1310
FIXED_NAMED_CAPTURES = %w[format version].freeze
1411

1512
attr_accessor :pattern, :translator, :app, :index, :options
@@ -20,31 +17,6 @@ class Route
2017
def_delegators :pattern, :path, :origin
2118
delegate Grape::Router::AttributeTranslator::ROUTE_ATTRIBUTES => :attributes
2219

23-
def method_missing(method_id, *arguments)
24-
match = ROUTE_ATTRIBUTE_REGEXP.match(method_id.to_s)
25-
if match
26-
method_name = match.captures.last.to_sym
27-
warn_route_methods(method_name, caller(1).shift)
28-
@options[method_name]
29-
else
30-
super
31-
end
32-
end
33-
34-
def respond_to_missing?(method_id, _)
35-
ROUTE_ATTRIBUTE_REGEXP.match?(method_id.to_s)
36-
end
37-
38-
def route_method
39-
warn_route_methods(:method, caller(1).shift, :request_method)
40-
request_method
41-
end
42-
43-
def route_path
44-
warn_route_methods(:path, caller(1).shift)
45-
pattern.path
46-
end
47-
4820
def initialize(method, pattern, **options)
4921
method_s = method.to_s
5022
method_upcase = Grape::Http::Headers.find_supported_method(method_s) || method_s.upcase
@@ -77,15 +49,6 @@ def params(input = nil)
7749
parsed ? parsed.delete_if { |_, value| value.nil? }.symbolize_keys : {}
7850
end
7951
end
80-
81-
private
82-
83-
def warn_route_methods(name, location, expected = nil)
84-
path, line = *location.scan(SOURCE_LOCATION_REGEXP).first
85-
path = File.realpath(path) if Pathname.new(path).relative?
86-
expected ||= name
87-
Grape.deprecator.warn("#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.")
88-
end
8952
end
9053
end
9154
end

spec/grape/api_spec.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -3050,7 +3050,6 @@ def static
30503050
expect(subject.routes.length).to eq(1)
30513051
route = subject.routes.first
30523052
expect(route.description).to eq('first method')
3053-
expect(route.route_foo).to be_nil
30543053
expect(route.params).to eq({})
30553054
expect(route.options).to be_a(Hash)
30563055
end
@@ -3095,7 +3094,7 @@ def static
30953094
get 'second'
30963095
end
30973096
expect(subject.routes.map do |route|
3098-
{ description: route.description, foo: route.route_foo, params: route.params }
3097+
{ description: route.description, foo: route.options[:foo], params: route.params }
30993098
end).to eq [
31003099
{ description: 'ns second', foo: 'bar', params: {} }
31013100
]

0 commit comments

Comments
 (0)