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.



30
31
32
33
34
35
# File 'lib/cukedep/feature-model.rb', line 30

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

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#lookupObject (readonly)

Inverse lookup: from the feature file => FeatureDependencies



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

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.



45
46
47
48
49
# File 'lib/cukedep/feature-model.rb', line 45

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



39
40
41
# File 'lib/cukedep/feature-model.rb', line 39

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