Sha256: c4c7a9aa20646c87fb89a30484a5022b48467e028deffefb3e7c81652dd3a777

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 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)
        route.verb.source =~ /\^?(\w*)\$/ ? $1.upcase : route.verb.source
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
yard-api-0.3.7 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.6 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.5 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.4 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.3 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.2 lib/yard-api/templates/helpers/route_helper.rb
yard-api-0.3.1 lib/yard-api/templates/helpers/route_helper.rb