Sha256: 409ed5e1acaf17aa830e39c2280cf52980f0f76fff5b66444ae015a0f9112790

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

require 'jsduck/logger'

module JsDuck
  module Process

    # Deals with inheriting class documentation.
    class InheritClass
      def initialize(relations)
        @relations = relations
      end

      # Inherits docs for class.
      #
      # For class we only inherit the value of :doc field.
      #
      # When the class we're inheriting from also has @inheritdoc tag,
      # we first recursively resolve the inheritance of that class and
      # only afterwards inherit to the current class.
      def resolve(cls)
        return unless cls[:inheritdoc]

        parent = find_parent(cls)
        if parent && parent[:inheritdoc]
          resolve(parent)
        end

        if parent
          cls[:doc] = parent[:doc] if cls[:doc].empty?
        end

        cls[:inheritdoc] = nil
      end

      private

      def find_parent(cls)
        if cls[:inheritdoc][:cls]
          # @inheritdoc MyClass
          parent = @relations[cls[:inheritdoc][:cls]]
          return warn("class not found", cls) unless parent
        else
          # @inheritdoc
          parent = cls.parent
          return warn("parent class not found", cls) unless parent
        end

        return parent
      end

      def warn(msg, cls)
        Logger.warn(:inheritdoc, "@inheritdoc #{cls[:inheritdoc][:cls]} - #{msg}", cls[:files][0])
        return nil
      end

    end

  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/process/inherit_class.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.10 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.9 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.8 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.7 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.5 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.4 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.3 lib/jsduck/process/inherit_class.rb
jsduck-troopjs-0.0.1 lib/jsduck/process/inherit_class.rb
jsduck-6.0.0beta lib/jsduck/process/inherit_class.rb
jsduck-5.3.4 lib/jsduck/process/inherit_class.rb
jsduck-5.3.3 lib/jsduck/process/inherit_class.rb
jsduck-5.3.2 lib/jsduck/process/inherit_class.rb
jsduck-5.3.1 lib/jsduck/process/inherit_class.rb