Class: JsDuck::BatchParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/batch_parser.rb

Overview

Parses of all input files. Input files are read from options object (originating from command line).

Class Method Summary collapse

Class Method Details

.parse(opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jsduck/batch_parser.rb', line 14

def self.parse(opts)
  cache = Cache.create(opts)

  results = Util::Parallel.map(opts.input_files) do |fname|
    Logger.log("Parsing", fname)

    begin
      source = Util::IO.read(fname)
      docs = nil

      unless docs = cache.read(fname, source)
        docs = Parser.new.parse(source, fname, opts)
        cache.write(fname, source, docs)
      end

      {
        :file => Source::File.new(source, docs, fname),
        :cache => cache.previous_entry,
      }
    rescue
      Logger.fatal_backtrace("Error while parsing #{fname}", $!)
      exit(1)
    end
  end

  cache.cleanup( results.map {|r| r[:cache] }.compact )

  return results.map {|r| r[:file] }
end