Sha256: dfe6fd017a81e4260cfb94b35352f4dc52401352ac4ec4b2454381f1ec400fde

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

module Inch
  module CodeObject
    module Provider
      module YARD
        # Parses the source tree (using YARD)
        class Parser
          IGNORE_TYPES      = [:macro]

          # Helper method to parse an instance with the given +args+
          #
          # @see #parse
          # @return [CodeObject::Provider::YARD::Parser] the instance that ran
          def self.parse(*args)
            parser = new
            parser.parse(*args)
            parser
          end

          # @param dir [String] directory
          # @param config [Inch::Config::Codebase] configuration for codebase
          # @return [void]
          def parse(dir, config)
            Dir.chdir(dir) do
              parse_yard_objects(config.included_files, config.excluded_files)
              inject_base_dir(dir)
            end
          end

          # @return [Array<YARD::Object::Base>]
          def objects
            @objects ||= parsed_objects.map do |o|
              YARD::Object.for(o) unless IGNORE_TYPES.include?(o.type)
            end.compact
          end

          private

          def parse_yard_objects(paths, excluded)
            YARD::Object.clear_cache
            ::YARD::Registry.clear
            ::YARD.parse(paths, excluded)
          end

          def inject_base_dir(dir)
            objects.each do |object|
              object.base_dir = dir

              object.aliases_fullnames.each do |fullname|
                alias_object = objects.find { |o| o.fullname == fullname }
                alias_object.aliased_object_fullname = object.fullname
              end
            end
          end

          def parsed_objects
            ::YARD::Registry.all
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inch-0.4.10 lib/inch/code_object/provider/yard/parser.rb
inch-0.4.9 lib/inch/code_object/provider/yard/parser.rb
inch-0.4.8 lib/inch/code_object/provider/yard/parser.rb