Module: YARD::Templates::Helpers::RouteHelper
- Defined in:
- lib/yard-api/templates/helpers/route_helper.rb
Class Method Summary collapse
- .api_methods_for_controller_and_action(controller, action) ⇒ Object
- .get_route_path(route) ⇒ Object
- .get_route_verb(route) ⇒ Object
- .matches_controller_and_action?(route, controller, action) ⇒ Boolean
- .routes_for(prefix) ⇒ Object
- .routes_for_yard_object(api_object) ⇒ Object
Class Method Details
.api_methods_for_controller_and_action(controller, action) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 22 def api_methods_for_controller_and_action(controller, action) @routes ||= routes_for('/') controller_path = [ YARD::APIPlugin..route_namespace, controller ].join('/') controller_path.gsub!(/^\/|_controller$/, '') @routes.find_all { |r| matches_controller_and_action?(r, controller_path, action) } end |
.get_route_path(route) ⇒ Object
29 30 31 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 29 def get_route_path(route) route.path.spec.to_s.gsub("(.:format)", "") end |
.get_route_verb(route) ⇒ Object
33 34 35 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 33 def get_route_verb(route) route.verb.source =~ /\^?(\w*)\$/ ? $1.upcase : route.verb.source end |
.matches_controller_and_action?(route, controller, action) ⇒ Boolean
17 18 19 20 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 17 def matches_controller_and_action?(route, controller, action) route.requirements[:controller] == controller && route.requirements[:action] == action end |
.routes_for(prefix) ⇒ Object
4 5 6 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 4 def routes_for(prefix) Rails.application.routes.set end |
.routes_for_yard_object(api_object) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/yard-api/templates/helpers/route_helper.rb', line 8 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 |