Class: Interdependence::DependencySetGraph

Inherits:
Graph
  • Object
show all
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

Examples:

Merge


dep1 # => { a: #<DependencyGraphSet: {1,2}> }
dep2 # => { a: #<DependencyGraphSet: {2,3}> }
dep1.merge(dep2) # => { a: #<DependencyGraphSet: {1,2,3}> }

See Also:

Direct Known Subclasses

ObservableDependencySetGraph

Instance Method Summary collapse

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

Parameters:

  • new_owner: (Dependency::Base)

    dependency key that will replace another

  • &blk (#call)

    block used to detect owner to replace

Returns:

  • (self)

    self with new owner



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

#cloneDependencySetGraph

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

Returns:



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

Returns:

See Also:

  • Interdependence::DependencySetGraph.`Hash`Hash#merge!`


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