Class: Molinillo::DependencyGraph::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/molinillo/dependency_graph/vertex.rb

Overview

A vertex in a Molinillo::DependencyGraph that encapsulates a #name and a #payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, payload) ⇒ Vertex

Initializes a vertex with the given name and payload.



25
26
27
28
29
30
31
# File 'lib/molinillo/dependency_graph/vertex.rb', line 25

def initialize(name, payload)
  @name = name.frozen? ? name : name.dup.freeze
  @payload = payload
  @explicit_requirements = []
  @outgoing_edges = []
  @incoming_edges = []
end

Instance Attribute Details

#explicit_requirementsArray<Object> (readonly)



16
17
18
# File 'lib/molinillo/dependency_graph/vertex.rb', line 16

def explicit_requirements
  @explicit_requirements
end

#incoming_edgesArray<Edge>



45
46
47
# File 'lib/molinillo/dependency_graph/vertex.rb', line 45

def incoming_edges
  @incoming_edges
end

#nameString



9
10
11
# File 'lib/molinillo/dependency_graph/vertex.rb', line 9

def name
  @name
end

#outgoing_edgesArray<Edge>



41
42
43
# File 'lib/molinillo/dependency_graph/vertex.rb', line 41

def outgoing_edges
  @outgoing_edges
end

#payloadObject



12
13
14
# File 'lib/molinillo/dependency_graph/vertex.rb', line 12

def payload
  @payload
end

#rootBoolean Also known as: root?



19
20
21
# File 'lib/molinillo/dependency_graph/vertex.rb', line 19

def root
  @root
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?



84
85
86
87
88
# File 'lib/molinillo/dependency_graph/vertex.rb', line 84

def ==(other)
  return true if equal?(other)
  shallow_eql?(other) &&
    successors.to_set == other.successors.to_set
end

#ancestor?(other) ⇒ Boolean Also known as: is_reachable_from?

Is there a path from ‘other` to `self` following edges in the dependency graph?



119
120
121
# File 'lib/molinillo/dependency_graph/vertex.rb', line 119

def ancestor?(other)
  other.path_to?(self)
end

#hashFixnum



103
104
105
# File 'lib/molinillo/dependency_graph/vertex.rb', line 103

def hash
  name.hash
end

#inspectString



78
79
80
# File 'lib/molinillo/dependency_graph/vertex.rb', line 78

def inspect
  "#{self.class}:#{name}(#{payload.inspect})"
end

#path_to?(other) ⇒ Boolean Also known as: descendent?

Is there a path from ‘self` to `other` following edges in the dependency graph?



110
111
112
# File 'lib/molinillo/dependency_graph/vertex.rb', line 110

def path_to?(other)
  equal?(other) || successors.any? { |v| v.path_to?(other) }
end

#predecessorsArray<Vertex>



49
50
51
# File 'lib/molinillo/dependency_graph/vertex.rb', line 49

def predecessors
  incoming_edges.map(&:origin)
end

#recursive_predecessorsArray<Vertex>



55
56
57
58
59
60
# File 'lib/molinillo/dependency_graph/vertex.rb', line 55

def recursive_predecessors
  vertices = predecessors
  vertices += Compatibility.flat_map(vertices, &:recursive_predecessors)
  vertices.uniq!
  vertices
end

#recursive_successorsArray<Vertex>



70
71
72
73
74
75
# File 'lib/molinillo/dependency_graph/vertex.rb', line 70

def recursive_successors
  vertices = successors
  vertices += Compatibility.flat_map(vertices, &:recursive_successors)
  vertices.uniq!
  vertices
end

#requirementsArray<Object>



35
36
37
# File 'lib/molinillo/dependency_graph/vertex.rb', line 35

def requirements
  incoming_edges.map(&:requirement) + explicit_requirements
end

#shallow_eql?(other) ⇒ Boolean



93
94
95
96
97
98
# File 'lib/molinillo/dependency_graph/vertex.rb', line 93

def shallow_eql?(other)
  return true if equal?(other)
  other &&
    name == other.name &&
    payload == other.payload
end

#successorsArray<Vertex>



64
65
66
# File 'lib/molinillo/dependency_graph/vertex.rb', line 64

def successors
  outgoing_edges.map(&:destination)
end