From 750667301d4bfdfb127c6f1a0360cb449e817e4d Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 14 Nov 2023 09:22:53 -0500 Subject: [PATCH 1/6] Add to_ary nil --- lib/grape/router/route.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/grape/router/route.rb b/lib/grape/router/route.rb index d5600df1c9..423661d975 100644 --- a/lib/grape/router/route.rb +++ b/lib/grape/router/route.rb @@ -86,6 +86,10 @@ def warn_route_methods(name, location, expected = nil) expected ||= name Grape.deprecator.warn("#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.") end + + def to_ary + nil + end end end end From ee8627f117cd57192849c1c0c62fce3af3be393e Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 14 Nov 2023 09:28:44 -0500 Subject: [PATCH 2/6] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d85e957e9..99f5d19d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ #### Fixes +* [#2370](https://github.com/ruby-grape/grape/pull/2370): Stop method_missing to_ary - [@ericproulx](https://github.com/ericproulx). * Your contribution here. ### 2.0.0 (2023/11/11) From 496764a24112735185cf79a8022d7e2c9e1a6ebc Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 19 Nov 2023 16:48:29 -0500 Subject: [PATCH 3/6] Remove method_missing and warning --- lib/grape/router/route.rb | 41 --------------------------------------- spec/grape/api_spec.rb | 3 +-- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/lib/grape/router/route.rb b/lib/grape/router/route.rb index 423661d975..ea49bac780 100644 --- a/lib/grape/router/route.rb +++ b/lib/grape/router/route.rb @@ -3,13 +3,10 @@ require 'grape/router/pattern' require 'grape/router/attribute_translator' require 'forwardable' -require 'pathname' module Grape class Router class Route - ROUTE_ATTRIBUTE_REGEXP = /route_([_a-zA-Z]\w*)/.freeze - SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/.freeze FIXED_NAMED_CAPTURES = %w[format version].freeze attr_accessor :pattern, :translator, :app, :index, :options @@ -20,31 +17,6 @@ class Route def_delegators :pattern, :path, :origin delegate Grape::Router::AttributeTranslator::ROUTE_ATTRIBUTES => :attributes - def method_missing(method_id, *arguments) - match = ROUTE_ATTRIBUTE_REGEXP.match(method_id.to_s) - if match - method_name = match.captures.last.to_sym - warn_route_methods(method_name, caller(1).shift) - @options[method_name] - else - super - end - end - - def respond_to_missing?(method_id, _) - ROUTE_ATTRIBUTE_REGEXP.match?(method_id.to_s) - end - - def route_method - warn_route_methods(:method, caller(1).shift, :request_method) - request_method - end - - def route_path - warn_route_methods(:path, caller(1).shift) - pattern.path - end - def initialize(method, pattern, **options) method_s = method.to_s method_upcase = Grape::Http::Headers.find_supported_method(method_s) || method_s.upcase @@ -77,19 +49,6 @@ def params(input = nil) parsed ? parsed.delete_if { |_, value| value.nil? }.symbolize_keys : {} end end - - private - - def warn_route_methods(name, location, expected = nil) - path, line = *location.scan(SOURCE_LOCATION_REGEXP).first - path = File.realpath(path) if Pathname.new(path).relative? - expected ||= name - Grape.deprecator.warn("#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.") - end - - def to_ary - nil - end end end end diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 161b561cbb..b67dcbe24e 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -3050,7 +3050,6 @@ def static expect(subject.routes.length).to eq(1) route = subject.routes.first expect(route.description).to eq('first method') - expect(route.route_foo).to be_nil expect(route.params).to eq({}) expect(route.options).to be_a(Hash) end @@ -3095,7 +3094,7 @@ def static get 'second' end expect(subject.routes.map do |route| - { description: route.description, foo: route.route_foo, params: route.params } + { description: route.description, foo: route.options[:foo], params: route.params } end).to eq [ { description: 'ns second', foo: 'bar', params: {} } ] From 09a87f79baed57d0aa477a36a5ab1cc0df8ff486 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sun, 19 Nov 2023 17:01:44 -0500 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aff3421eb4..3fea64a0eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ #### Fixes -* [#2370](https://github.com/ruby-grape/grape/pull/2370): Stop method_missing to_ary - [@ericproulx](https://github.com/ericproulx). +* [#2370](https://github.com/ruby-grape/grape/pull/2370): Remove route_xyz method_missing deprecation - [@ericproulx](https://github.com/ericproulx). * [#2372](https://github.com/ruby-grape/grape/pull/2372): Fix `declared` method for hash params with overlapping names - [@jcagarcia](https://github.com/jcagarcia). * Your contribution here. From c90f68167b7685f2932705e6b24858a1fec15fd7 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 19 Nov 2023 21:15:27 -0500 Subject: [PATCH 5/6] Add upgrading notes Replace route_params by params --- README.md | 6 +++--- UPGRADING.md | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 58d391f7bd..bef2012ba3 100644 --- a/README.md +++ b/README.md @@ -3483,7 +3483,7 @@ You can access the controller params, headers, and helpers through the context w Grape routes can be reflected at runtime. This can notably be useful for generating documentation. -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`. +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`. ```ruby class TwitterAPI < Grape::API @@ -3506,7 +3506,7 @@ TwitterAPI::routes[0].description # => 'Includes custom settings.' TwitterAPI::routes[0].settings[:custom] # => { key: 'value' } ``` -Note that `Route#route_xyz` methods have been deprecated since 0.15.0. +Note that `Route#route_xyz` methods have been deprecated since 0.15.0 and removed since 2.0.1 Please use `Route#xyz` instead. @@ -3526,7 +3526,7 @@ class MyAPI < Grape::API requires :id, type: Integer, desc: 'Identity.' end get 'params/:id' do - route.route_params[params[:id]] # yields the parameter description + route.params[params[:id]] # yields the parameter description end end ``` diff --git a/UPGRADING.md b/UPGRADING.md index b9877889ee..07c950f4f1 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,14 @@ Upgrading Grape =============== +### Upgrading to >= 2.0.1 + +#### Grape::Router::Route.route_xxx methods have been removed + +- `route_method` is accessible through `request_method` +- `route_path` is accessible through `path` +- Any other `route_xyz` are accessible through `options[xyz]` + ### Upgrading to >= 2.0.0 #### Headers From b1f1662597697effa74245a4bada7561ed172395 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Mon, 20 Nov 2023 08:15:05 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bef2012ba3..2e124b7566 100644 --- a/README.md +++ b/README.md @@ -3506,7 +3506,7 @@ TwitterAPI::routes[0].description # => 'Includes custom settings.' TwitterAPI::routes[0].settings[:custom] # => { key: 'value' } ``` -Note that `Route#route_xyz` methods have been deprecated since 0.15.0 and removed since 2.0.1 +Note that `Route#route_xyz` methods have been deprecated since 0.15.0 and removed since 2.0.1. Please use `Route#xyz` instead.