Class: Interdependence::DependencySetGraph
- Defined in:
- lib/interdependence/dependency_set_graph.rb
Overview
DependencySetGraph - extension of graph structure back by DependencySet
-
Extends our graph data structure
-
Overrides ‘#merge!` to merge both keys and set values
Direct Known Subclasses
Instance Method Summary collapse
-
#change_owner(new_owner:, &blk) ⇒ self
private
Replace the owner of a certain set in the graph.
-
#clone ⇒ DependencySetGraph
private
clone a DependencySetGraph.
-
#merge!(*args) ⇒ DependencySetGraph
private
Merge two dependency set graphs.
Methods inherited from Graph
#initialize, #tsort_each_child, #tsort_fetch
Constructor Details
This class inherits a constructor from Interdependence::Graph
Instance Method Details
#change_owner(new_owner:, &blk) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replace the owner of a certain set in the graph
39 40 41 42 43 44 45 46 47 |
# File 'lib/interdependence/dependency_set_graph.rb', line 39 def change_owner(new_owner:, &blk) old_owner = keys.detect(&blk) tap do |graph| graph[new_owner] = delete(old_owner) do fail 'could not detect or delete key for replacement' end end end |
#clone ⇒ DependencySetGraph
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
clone a DependencySetGraph
24 25 26 27 28 |
# File 'lib/interdependence/dependency_set_graph.rb', line 24 def clone each_with_object(self.class.new) do |(parent, dependencies), clone| clone[parent] = dependencies.clone end end |
#merge!(*args) ⇒ DependencySetGraph
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Merge two dependency set graphs
Passes a block to ‘Hash#merge!` then instructs how two sets from different dependency graphs should be joined
60 61 62 63 64 |
# File 'lib/interdependence/dependency_set_graph.rb', line 60 def merge!(*args) super do |_, dependencies, other_dependencies| dependencies.merge(other_dependencies) end end |