class JsDuck::Merger
Takes data from comment and code that follows it and combines these two pieces of information into one. The code comes from JsDuck::JS::Ast and comment from JsDuck::Doc::Processor
.
The main method merge() produces a hash as a result.
Private Class Methods
can_be_autodetected?(docs, code)
click to toggle source
True if the name detected from code matches with explicitly documented name. Also true when no explicit name documented.
Note: This method is also called from ParamsMerger
.
# File lib/jsduck/merger.rb, line 72 def self.can_be_autodetected?(docs, code) docs[:name] == nil || docs[:name] == code[:name] end
Public Instance Methods
merge(docset, filename="", linenr=0)
click to toggle source
Takes a docset and merges the :comment and :code inside it, producing hash as a result.
# File lib/jsduck/merger.rb, line 15 def merge(docset, filename="", linenr=0) docs = docset[:comment] code = process_code(docset[:tagname], docset[:code]) h = { :tagname => docset[:tagname], :name => docs[:name] || code[:name] || "", :autodetected => code[:autodetected] || {}, :files => [{:filename => filename, :linenr => linenr}], } general_merge(h, docs, code) invoke_merge_in_member_tag(h, docs, code) # Needs to be calculated last, as it relies on the existance of # :name, :static and :tagname fields. h[:id] = JsDuck::Class.member_id(h) h end
Private Instance Methods
general_merge(h, docs, code)
click to toggle source
Applies default merge algorithm to the rest of the data.
# File lib/jsduck/merger.rb, line 49 def general_merge(h, docs, code) # Add all items in docs not already in result. docs.each_pair do |key, value| h[key] = value unless h[key] end # Add all items in code not already in result and mark them as # auto-detected. But only if the explicit and auto-detected # names don't conflict. if Merger.can_be_autodetected?(docs, code) code.each_pair do |key, value| unless h[key] h[key] = value mark_autodetected(h, key) end end end end
invoke_merge_in_member_tag(h, docs, code)
click to toggle source
Invokes the merge
method in corresponding member or :class tag.
# File lib/jsduck/merger.rb, line 44 def invoke_merge_in_member_tag(h, docs, code) TagRegistry.get_by_name(h[:tagname]).merge(h, docs, code) end
mark_autodetected(h, key)
click to toggle source
Stores the key as flag into h
# File lib/jsduck/merger.rb, line 77 def mark_autodetected(h, key) h[:autodetected][key] = true end
process_code(tagname, code)
click to toggle source
Applies processing to extract fields relevant to the member type.
# File lib/jsduck/merger.rb, line 39 def process_code(tagname, code) TagRegistry.get_by_name(tagname).process_code(code) end