Class: LazyApiDoc::RouteParser
- Inherits:
-
Object
- Object
- LazyApiDoc::RouteParser
- Defined in:
- lib/lazy_api_doc/route_parser.rb
Class Method Summary collapse
Class Method Details
.find_by(example) ⇒ Object
3 4 5 6 7 |
# File 'lib/lazy_api_doc/route_parser.rb', line 3 def self.find_by(example) r = routes.find do |r| r['verb'].include?(example.verb) && example.params.slice(*r['defaults'].keys) == r['defaults'] end end |
.format(route) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lazy_api_doc/route_parser.rb', line 15 def self.format(route) route = ActionDispatch::Routing::RouteWrapper.new(route) { 'doc_path' => route.path.gsub("(.:format)", "").gsub(/(:\w+)/, '{\1}').delete(":"), 'path_params' => route.path.gsub("(.:format)", "").scan(/:\w+/).map { |p| p.delete(":") }, 'controller' => route.controller, 'action' => route.action, 'verb' => route.verb.split('|'), 'defaults' => route.defaults.transform_keys(&:to_s) } end |
.routes ⇒ Object
9 10 11 12 13 |
# File 'lib/lazy_api_doc/route_parser.rb', line 9 def self.routes return @routes if defined?(@routes) @routes = Rails.application.routes.routes.map { |route| format(route) } end |