Sha256: db6e9baaf218f2796804d1894b4e4f08658c5144449cbd94f8e56997b55f561b

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

require 'pathname'

module Codependency
  class Node
    def initialize( filename, parser )
      raise Errno::ENOENT, filename unless File.exist?( filename )
      @filename = filename
      @parser   = parser
    end
    attr_reader :filename, :parser

    ##
    # all of this node's edges
    def edges
      @edges ||= begin
        parser.parse( filename ).map do |f|
          dirname.join( "#{f}#{extname}" ).to_s
        end
      end
    end

    ##
    # a string representing this node's edges, formatted for `tsort`.
    def dependencies
      edges.map { |edge| [ filename, edge ] }.flatten.join ' '
    end

    protected

    def dirname
      path.dirname
    end

    def extname
      path.extname
    end

    def path
      @path ||= Pathname.new filename
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codependency-0.3.0 lib/codependency/node.rb