Sha256: d77600bd280e6c7dc056500aeecadaaa5af49fbcbbaae2fdf6225fabe54e4cce
Contents?: true
Size: 1.35 KB
Versions: 5
Compression:
Stored size: 1.35 KB
Contents
module YARD::Templates::Helpers module RouteHelper class << self def routes_for(prefix) Rails.application.routes.set end def routes_for_yard_object(api_object) controller_name = api_object.parent.path.underscore controller_name.sub!('_controller', '') unless controller_name.include?('/') action = api_object.path.sub(/^.*#/, '').sub(/_with_.*$/, '') api_methods_for_controller_and_action(controller_name, action) end def matches_controller_and_action?(route, controller, action) route.requirements[:controller] == controller && route.requirements[:action] == action end def api_methods_for_controller_and_action(controller, action) @routes ||= routes_for('/') controller_path = [ YARD::APIPlugin.options.route_namespace, controller ].join('/') controller_path.gsub!(/^\/|_controller$/, '') @routes.find_all { |r| matches_controller_and_action?(r, controller_path, action) } end def get_route_path(route) route.path.spec.to_s.gsub("(.:format)", "") end def get_route_verb(route) verb = route.verb case verb when Regexp verb.source =~ /\^?(\w*)\$/ ? $1.upcase : verb.source when String verb else "???" end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems