Class: Cukedep::FeatureModel::DepGraph

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/cukedep/feature-model.rb

Overview

Helper class used internally by FeatureModel class. Purpose: to try to create a valid dependency graph and perform a topological sort of the nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theDependencies) ⇒ DepGraph

Returns a new instance of DepGraph.



27
28
29
30
31
32
# File 'lib/cukedep/feature-model.rb', line 27

def initialize(theDependencies)
  @dependencies = theDependencies
  @lookup = dependencies.each_with_object({}) do |f_deps, subresult|
    subresult[f_deps.dependee] = f_deps
  end
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



22
23
24
# File 'lib/cukedep/feature-model.rb', line 22

def dependencies
  @dependencies
end

#lookupObject (readonly)

Inverse lookup: from the feature file => FeatureDependencies



25
26
27
# File 'lib/cukedep/feature-model.rb', line 25

def lookup
  @lookup
end

Instance Method Details

#tsort_each_child(aDependency, &aBlock) ⇒ Object

Method required by TSort module. It is used to iterate over all the children nodes of the given node.



42
43
44
45
46
# File 'lib/cukedep/feature-model.rb', line 42

def tsort_each_child(aDependency, &aBlock)
  dependents = aDependency.dependents
  children = dependents.map { |feature| lookup[feature] }
  children.each(&aBlock)
end

#tsort_each_node(&aBlock) ⇒ Object

Method required by TSort module. It is used to iterate over all the nodes of the dependency graph



36
37
38
# File 'lib/cukedep/feature-model.rb', line 36

def tsort_each_node(&aBlock)
  return dependencies.each(&aBlock)
end