Sha256: b4bf5bae0c510eb4d01a74282bd3fccc2ef1746f82ca3538ae73913ff9681e32

Contents?: true

Size: 843 Bytes

Versions: 5

Compression:

Stored size: 843 Bytes

Contents

module JsDuck

  # Checks for circular dependencies
  class CircularDeps

    # Checks class for circular dependencies.
    #
    # When all OK, returns false.
    #
    # When circular dependencies found returns a string describing the
    # problematic dependency chain e.g. "Foo extends Bar mixins Foo".
    def check(cls, names = [])
      names += [cls[:name]]

      if cls.parent && chain = track_circular(" extends ", cls.parent, names)
        return chain
      end

      cls.mixins.each do |mixin|
        if chain = track_circular(" mixins ", mixin, names)
          return chain
        end
      end

      false
    end

    def track_circular(type, cls, names)
      names += [type]
      if names.include?(cls[:name])
        (names + [cls[:name]]).join("")
      else
        check(cls, names)
      end
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jsduck-4.5.1 lib/jsduck/circular_deps.rb
jsduck-4.5.0 lib/jsduck/circular_deps.rb
jsduck-4.4.1 lib/jsduck/circular_deps.rb
jsduck-4.4.0 lib/jsduck/circular_deps.rb
jsduck-4.3.2 lib/jsduck/circular_deps.rb