class LazyApiDoc::RouteParser

Attributes

action[R]
controller[R]
verb[R]

Public Class Methods

new(controller, action, verb) click to toggle source
# File lib/lazy_api_doc/route_parser.rb, line 5
def initialize(controller, action, verb)
  @controller = controller
  @action = action
  @verb = verb
end
routes() click to toggle source
# File lib/lazy_api_doc/route_parser.rb, line 15
def self.routes
  return @routes if defined?(@routes)

  all_routes = Rails.application.routes.routes
  require "action_dispatch/routing/inspector"
  inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
  @routes = inspector.format(JsonRoutesFormatter.new, ENV["CONTROLLER"])
end

Public Instance Methods

route() click to toggle source
# File lib/lazy_api_doc/route_parser.rb, line 11
def route
  self.class.routes.find { |r| r[:action] == action && r[:controller] == controller && r[:verb].include?(verb) }
end