Method: ComputedModel::DepGraph.merge

Defined in:
lib/computed_model/dep_graph.rb

.merge(graphs) ⇒ ComputedModel::DepGraph

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.

Parameters:

Returns:



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/computed_model/dep_graph.rb', line 104

def self.merge(graphs)
  new_graph = ComputedModel::DepGraph.new
  nodes_by_name = graphs.flat_map(&:nodes).group_by(&:name)
  nodes_by_name.each do |name, nodes|
    type = nodes.first.type
    raise ArgumentError, "Field #{name} has multiple different types" unless nodes.all? { |node| node.type == type }

    new_graph << ComputedModel::DepGraph::Node.new(type, name, nodes.map { |n| n.edges.transform_values { |e| e.spec } })
  end
  new_graph
end