class Guacamole::Transaction::TxEdgeCollection
Attributes
ea[R]
edge_collection[R]
from_models[R]
model[R]
old_edges[R]
to_models[R]
Public Class Methods
new(ea, model)
click to toggle source
# File lib/guacamole/transaction.rb, line 14 def initialize(ea, model) @ea = ea @model = model @edge_collection = EdgeCollection.for(ea.edge_class) init end
Public Instance Methods
edge_collection_for_transaction()
click to toggle source
# File lib/guacamole/transaction.rb, line 81 def edge_collection_for_transaction { name: edge_collection.collection_name, fromVertices: from_vertices, toVertices: to_vertices_with_only_existing_documents, edges: edges, oldEdges: old_edges } end
edges()
click to toggle source
# File lib/guacamole/transaction.rb, line 69 def edges from_vertices.each_with_object([]) do |from_vertex, edges| to_vertices.each do |to_vertex| edges << { _from: from_vertex[:_id] || from_vertex[:object_id], _to: to_vertex[:_id] || to_vertex[:object_id], attributes: {} } end end end
from_vertices()
click to toggle source
# File lib/guacamole/transaction.rb, line 41 def from_vertices from_models.map do |m| { object_id: m.object_id, collection: edge_collection.edge_class.from_collection.collection_name, document: select_mapper.call(m).model_to_document(m), _key: m.key, _id: m._id } end end
init()
click to toggle source
# File lib/guacamole/transaction.rb, line 22 def init case model when ea.edge_class.from_collection.model_class @from_models = [model] @to_models = [ea.get_value(model)].compact.flatten @old_edges = edge_collection.by_example(_from: model._id).map(&:key) when ea.edge_class.to_collection.model_class @to_models = [model] @from_models = [ea.get_value(model)].compact.flatten @old_edges = edge_collection.by_example(_to: model._id).map(&:key) else raise RuntimeError end end
select_mapper()
click to toggle source
# File lib/guacamole/transaction.rb, line 37 def select_mapper ->(m) { edge_collection.mapper_for_start(m) } end
to_vertices()
click to toggle source
# File lib/guacamole/transaction.rb, line 53 def to_vertices to_models.map do |m| { object_id: m.object_id, collection: edge_collection.edge_class.to_collection.collection_name, document: select_mapper.call(m).model_to_document(m), _key: m.key, _id: m._id } end end
to_vertices_with_only_existing_documents()
click to toggle source
# File lib/guacamole/transaction.rb, line 65 def to_vertices_with_only_existing_documents to_vertices.select { |v| v[:_key].nil? } end