Class: Molinillo::DependencyGraph::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/molinillo/dependency_graph.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

Returns a new instance of Vertex.

Parameters:



179
180
181
182
183
184
185
# File 'lib/molinillo/dependency_graph.rb', line 179

def initialize(name, payload)
  @name = name
  @payload = payload
  @explicit_requirements = []
  @outgoing_edges = []
  @incoming_edges = []
end

Instance Attribute Details

#explicit_requirementsArrary<Object> (readonly)

Returns the explicit requirements that required this vertex.

Returns:

  • (Arrary<Object>)

    the explicit requirements that required this vertex



171
172
173
# File 'lib/molinillo/dependency_graph.rb', line 171

def explicit_requirements
  @explicit_requirements
end

#incoming_edgesArray<Edge>

Returns the edges of #graph that have self as their Edge#destination.

Returns:



199
200
201
# File 'lib/molinillo/dependency_graph.rb', line 199

def incoming_edges
  @incoming_edges
end

#nameString

Returns the name of the vertex.

Returns:

  • (String)

    the name of the vertex



164
165
166
# File 'lib/molinillo/dependency_graph.rb', line 164

def name
  @name
end

#outgoing_edgesArray<Edge>

Returns the edges of #graph that have self as their Edge#origin.

Returns:

  • (Array<Edge>)

    the edges of #graph that have self as their Edge#origin



195
196
197
# File 'lib/molinillo/dependency_graph.rb', line 195

def outgoing_edges
  @outgoing_edges
end

#payloadObject

Returns the payload the vertex holds.

Returns:

  • (Object)

    the payload the vertex holds



167
168
169
# File 'lib/molinillo/dependency_graph.rb', line 167

def payload
  @payload
end

#rootBoolean Also known as: root?

Returns whether the vertex is considered a root vertex.

Returns:

  • (Boolean)

    whether the vertex is considered a root vertex



174
175
176
# File 'lib/molinillo/dependency_graph.rb', line 174

def root
  @root
end

Instance Method Details

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

Returns whether the two vertices are equal, determined by a recursive traversal of each #successors.

Returns:

  • (Boolean)

    whether the two vertices are equal, determined by a recursive traversal of each #successors



238
239
240
241
# File 'lib/molinillo/dependency_graph.rb', line 238

def ==(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?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #graph



270
271
272
# File 'lib/molinillo/dependency_graph.rb', line 270

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

#hashFixnum

Returns a hash for the vertex based upon its #name.

Returns:

  • (Fixnum)

    a hash for the vertex based upon its #name



254
255
256
# File 'lib/molinillo/dependency_graph.rb', line 254

def hash
  name.hash
end

#inspectString

Returns a string suitable for debugging.

Returns:

  • (String)

    a string suitable for debugging



232
233
234
# File 'lib/molinillo/dependency_graph.rb', line 232

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?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #graph



261
262
263
# File 'lib/molinillo/dependency_graph.rb', line 261

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

#predecessorsArray<Vertex>

Returns the vertices of #graph that have an edge with self as their Edge#destination.

Returns:



203
204
205
# File 'lib/molinillo/dependency_graph.rb', line 203

def predecessors
  incoming_edges.map(&:origin)
end

#recursive_predecessorsArray<Vertex>

Returns the vertices of #graph where self is a #descendent?.

Returns:



209
210
211
212
213
214
# File 'lib/molinillo/dependency_graph.rb', line 209

def recursive_predecessors
  vertices = predecessors
  vertices += vertices.map(&:recursive_predecessors).flatten(1)
  vertices.uniq!
  vertices
end

#recursive_successorsArray<Vertex>

Returns the vertices of #graph where self is an #ancestor?.

Returns:



224
225
226
227
228
229
# File 'lib/molinillo/dependency_graph.rb', line 224

def recursive_successors
  vertices = successors
  vertices += vertices.map(&:recursive_successors).flatten(1)
  vertices.uniq!
  vertices
end

#requirementsArray<Object>

Returns all of the requirements that required this vertex.

Returns:

  • (Array<Object>)

    all of the requirements that required this vertex



189
190
191
# File 'lib/molinillo/dependency_graph.rb', line 189

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

#shallow_eql?(other) ⇒ Boolean

Returns whether the two vertices are equal, determined solely by #name and #payload equality.

Returns:

  • (Boolean)

    whether the two vertices are equal, determined solely by #name and #payload equality



245
246
247
248
249
# File 'lib/molinillo/dependency_graph.rb', line 245

def shallow_eql?(other)
  other &&
    name == other.name &&
    payload == other.payload
end

#successorsArray<Vertex>

Returns the vertices of #graph that have an edge with self as their Edge#origin.

Returns:

  • (Array<Vertex>)

    the vertices of #graph that have an edge with self as their Edge#origin



218
219
220
# File 'lib/molinillo/dependency_graph.rb', line 218

def successors
  outgoing_edges.map(&:destination)
end