Sha256: eff6aafe96ff71aee461abe9f4885af2c93b965823a37c670b30ba8b5ea0178b

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

module YARD
  module APIPlugin
    class Verifier < ::YARD::Verifier
      def initialize(verbose=false)
        @verbose = verbose
        @routes = {}
        super()
      end

      def run(list)
        relevant = list.select { |o| relevant_object?(o) }

        if @verbose && relevant.any?
          logger.debug "#{relevant.length}/#{list.length} objects are relevant:"

          relevant.each do |object|
            logger.debug "\t- #{object.path}"
          end
        end

        relevant
      end

      def relevant_object?(object)
        case object.type
        when :root, :module, :constant
          false
        when :api
          true
        when :method
          return false if object.has_tag?(:internal) || !object.has_tag?(:API)
          routes = @routes[object.object_id]
          routes ||= begin
            @routes[object.object_id] = YARD::Templates::Helpers::RouteHelper.routes_for_yard_object(object)
          end

          if routes.empty?
            logger.warn (
              "API Endpoint #{object.path}# has no routes defined " +
              "ib routes.rb and will be ignored."
            )
          end

          routes.any?
        when :class
          return false if object.has_tag?(:internal) || !object.has_tag?(:API)
          true
        else
          object.parent.nil? && relevant_object?(object.parent)
        end
      end

      def logger
        ::YARD::APIPlugin.logger
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
yard-api-1.0.1 lib/yard-api/verifier.rb
yard-api-1.0.0 lib/yard-api/verifier.rb
yard-api-0.3.7 lib/yard-api/verifier.rb
yard-api-0.3.6 lib/yard-api/verifier.rb
yard-api-0.3.5 lib/yard-api/verifier.rb
yard-api-0.3.4 lib/yard-api/verifier.rb
yard-api-0.3.3 lib/yard-api/verifier.rb
yard-api-0.3.2 lib/yard-api/verifier.rb
yard-api-0.3.1 lib/yard-api/verifier.rb