Sha256: c6ab07987d26c981df55e6935aea0157fdfd5fcea41f67145c0d0d4c4cacb544

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

module Codependency
  class Graph
    def initialize( start, options={} )
      @options = options
      @nodes   = Hash.new { |h, k| h[ k ] = Node.new( k, parser ) }
      @start   = @nodes[ start ]
    end

    def files
      [ ].tap { |list| resolve @start, list }.reverse.map &:filename
    end

    protected

    def resolve( node, list )
      list << node # TODO if the node were in the list here,
                   # would that indicate a circular dependency?
      node.dependencies.map { |filename| @nodes[ filename ] }.each do |dep|
        if list.include?( dep )
          list << list.slice!( list.index( dep ) )
        else
          resolve dep, list
        end
      end
    end

    def parser
      @parser ||= Parser.new @options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codependency-0.2.0 lib/codependency/graph.rb