Module: Aserto::Rails::Utils
- Defined in:
- lib/aserto/rails/utils.rb
Class Method Summary collapse
-
.route(request) ⇒ Object
Finds the Rails route for the given path.
Class Method Details
.route(request) ⇒ Object
Finds the Rails route for the given path. If the route is not found, returns nil. If the route is found, returns a hash with the following keys: :path :action
Eg: route(“/api/v1/users/1”) => {
:action => :GET,
:path => "/api/v1/users/:id" }
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aserto/rails/utils.rb', line 17 def route(request) return unless defined? ::Rails path = request.path_info route = ::Rails.application.routes.routes.to_a.find do |cr| cr.path.to_regexp.match?(path) end return unless route { path: route.path.spec.to_s.sub("(.:format)", ""), action: request.request_method.to_sym } end |