Commit 29e3d021 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move method name detection to Tag::Method.

Also the @constructor plays part in determining the name.
To make the two work together inspect the hash passed in to #process_doc
and only set the method name when needed.
parent 049e7c50
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ module JsDuck
      def create_method(docs, doc_map)
        return add_shared({
            :tagname => :method,
            :name => detect_name(:method, doc_map),
            :doc => detect_doc(docs),
            :params => detect_params(doc_map),
            :return => detect_return(doc_map),
@@ -120,12 +119,7 @@ module JsDuck
      end

      def detect_name(tagname, doc_map)
        name = extract(doc_map, tagname, :name)
        if name
          name
        else
          doc_map[:constructor] ? "constructor" : nil
        end
        extract(doc_map, tagname, :name)
      end

      def extract(doc_map, tagname, propname = nil)
+7 −0
Original line number Diff line number Diff line
@@ -4,11 +4,18 @@ module JsDuck::Tag
  class Constructor < Tag
    def initialize
      @pattern = "constructor"
      @key = :constructor
    end

    # @constructor
    def parse(p)
      {:tagname => :constructor}
    end

    # The method name will become "constructor" unless a separate
    # @method tag already supplied the name.
    def process_doc(h, tags)
      h[:name] = "constructor" unless h[:name]
    end
  end
end
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ module JsDuck::Tag
  class Method < Tag
    def initialize
      @pattern = "method"
      @key = :method
      @member_type = :method
    end

@@ -15,5 +16,11 @@ module JsDuck::Tag
        :name => p.hw.ident,
      }
    end

    # Onle sets the name when it's actually specified.
    # Otherwise we might overwrite name coming from @constructor.
    def process_doc(h, tags)
      h[:name] = tags[0][:name] if tags[0][:name]
    end
  end
end