class JsDuck::Process::Importer
Reads in JSDuck exports of different versions of docs.
Public Instance Methods
import(versions)
click to toggle source
Reads in data for all versions, returning array of version/class-data pairs. We don't use a hash to preserve the order of versions (from oldest to newest).
# File lib/jsduck/process/importer.rb, line 14 def import(versions) versions.map do |ver| { :version => ver[:version], :classes => ver[:path] ? read(ver) : current_version, } end end
Private Instance Methods
correct_format?(json)
click to toggle source
# File lib/jsduck/process/importer.rb, line 59 def correct_format?(json) json["members"].is_a?(Array) end
current_version()
click to toggle source
# File lib/jsduck/process/importer.rb, line 25 def current_version JsDuck::Util::NullObject.new( :[] => JsDuck::Util::NullObject.new( # class :[] => JsDuck::Util::NullObject.new( # member :length => 1.0 / 0))) # params count == Infinity end
ensure_correct_format(path)
click to toggle source
# File lib/jsduck/process/importer.rb, line 47 def ensure_correct_format(path) # Read first JSON file in import dir json = Util::Json.read(Dir[path + "/*.json"].first) unless correct_format?(json) Logger.fatal("Bad format for importing: #{path}") Logger.fatal("Export format changed in 5.0.0 beta 2.") Logger.fatal("Maybe you forgot to re-generate the exports with new JSDuck.") exit(1) end end
members_id_index(json)
click to toggle source
creates index of all class members
# File lib/jsduck/process/importer.rb, line 64 def members_id_index(json) index = {} json["members"].each do |m| index[m["id"]] = m["params"] ? m["params"].map {|p| p["name"] } : true end index end
read(ver)
click to toggle source
Reads in data from all .json files in directory
# File lib/jsduck/process/importer.rb, line 33 def read(ver) ensure_correct_format(ver[:path]) # Map list of files into pairs of (classname, members-hash) pairs = Util::Parallel.map(Dir[ver[:path] + "/*.json"]) do |filename| Logger.log("Importing #{ver[:version]}", filename) json = Util::Json.read(filename) [json["name"], members_id_index(json)] end # Turn key-value pairs array into hash return Hash[ pairs ] end