Sha256: f50f4d0fdeaf9a6696e6418ac4a935b006af7e91cff7a44f9de83c70e610d9d1

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

module DepGraph

  #A node knows its dependables
  class Node
    include Comparable
    attr_reader :name

    def initialize(node_uri)
      fail 'Empty uris are not allowed' if node_uri.empty?
      @name = node_uri
      @dependencies = []
    end
      
    def to_str
      @name
    end
    
    def <=> other_node
      @name <=> other_node.to_str
    end
    
    def eql? other_node
      (self <=> other_node) == 0
    end
    
    def hash
      @name.hash
    end
    
    def depends_on node
      node = Node.new(node) unless node.respond_to? :name
      
      @dependencies << node
    end
    
    def depends_on? node
      @dependencies.include? node
    end

    def dependencies
      @dependencies
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
depgraph-0.11.0 lib/node.rb
DepGraph-0.10.0 lib/node.rb
DepGraph-0.9.0 lib/node.rb