Sha256: dcbb99d6e165f06895b4943aa56540089c166ad6ed99bfd1a6db257fdd259d4a

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

require 'json'
require 'inch/language/nodejs/provider/jsdoc/object'

module Inch
  module Language
    module Nodejs
      module Provider
        module JSDoc
          # Parses the source tree (using JSDoc)
          class Parser
            IGNORE_TYPES = %w(member package)

            attr_reader :parsed_objects

            # Helper method to parse an instance with the given +args+
            #
            # @see #parse
            # @return [CodeObject::Provider::JSDoc::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_objects(config.included_files, config.excluded_files,
                              config.read_dump_file)
              end
            end

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

            private

            def parse_objects(paths, excluded, read_dump_file = nil)
              if read_dump_file.nil?
                fail 'NodeJS analysis only works with --read-from-dump.'
              else
                output = File.read(read_dump_file)
              end
              @parsed_objects = JSON[output]['objects']
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inch-0.5.0.rc11 lib/inch/language/nodejs/provider/jsdoc/parser.rb
inch-0.5.0.rc10 lib/inch/language/nodejs/provider/jsdoc/parser.rb
inch-0.5.0.rc9 lib/inch/language/nodejs/provider/jsdoc/parser.rb
inch-0.5.0.rc8 lib/inch/language/nodejs/provider/jsdoc/parser.rb
inch-0.5.0.rc7 lib/inch/language/nodejs/provider/jsdoc/parser.rb
inch-0.5.0.rc6 lib/inch/language/nodejs/provider/jsdoc/parser.rb