Методы route_xxx, такие как route_method, устарели... (Grape API)
У меня есть задача rake, чтобы перечислить мои маршруты API Grape. Когда я запускаю его, я получаю:
% bundle exec rake api:routes
/Users/private/my_project/lib/tasks/api/routes.rake:7: The route_xxx methods such as route_method have been deprecated, please use request_method.
/Users/private/my_project/lib/tasks/api/routes.rake:8: The route_xxx methods such as route_path have been deprecated, please use path.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
GET /api/widget/color(.:format)
/Users/private/my_project/lib/tasks/api/routes.rake:7: The route_xxx methods such as route_method have been deprecated, please use request_method.
/Users/private/my_project/lib/tasks/api/routes.rake:8: The route_xxx methods such as route_path have been deprecated, please use path.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
GET /api/widget/flavor(.:format)
/Users/private/my_project/lib/tasks/api/routes.rake:7: The route_xxx methods such as route_method have been deprecated, please use request_method.
/Users/private/my_project/lib/tasks/api/routes.rake:8: The route_xxx methods such as route_path have been deprecated, please use path.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
/Users/private/my_project/lib/tasks/api/routes.rake:9: The route_xxx methods such as route_version have been deprecated, please use version.
POST /api/widget/order(.:format)
...repeat x100...
Моя рейк-задача:
namespace :api do
desc 'API Routes'
task routes: :environment do
MyApi.routes.each do |api|
method = api.route_method || '??'
path = api.route_path || '--'
path = path.gsub(':version', api.route_version) if path && api.route_version
puts " #{method.ljust(10)} #{path}"
end
end
end
1 ответ
Replace the methods as suggested in the deprecation warnings:
namespace :api do
desc 'API Routes'
task routes: :environment do
Alex::Base.routes.each do |api|
method = api.request_method || '??'
path = api.path || '--'
path = path.gsub(':version', api.version) if path && api.version
puts " #{method.ljust(10)} #{path}"
end
end
end
Voila! No more warnings:
bundle exec rake api:routes
GET /api/widget/color(.:format)
GET /api/widget/flavor(.:format)
POST /api/widget/order(.:format)
...etc...