class Guacamole::Transaction
Attributes
collection[R]
model[R]
Public Class Methods
new(options)
click to toggle source
# File lib/guacamole/transaction.rb, line 98 def initialize(options) @collection = options[:collection] @model = options[:model] end
run(options)
click to toggle source
# File lib/guacamole/transaction.rb, line 93 def run(options) new(options).execute_transaction end
Public Instance Methods
edge_collections()
click to toggle source
# File lib/guacamole/transaction.rb, line 129 def edge_collections real_edge_collections.present? ? real_edge_collections : fake_edge_collections end
execute_transaction()
click to toggle source
# File lib/guacamole/transaction.rb, line 157 def execute_transaction transaction.execute(transaction_params) end
fake_edge_collections()
click to toggle source
# File lib/guacamole/transaction.rb, line 109 def fake_edge_collections fake_vertex = { object_id: model.object_id, collection: collection.collection_name, document: mapper.model_to_document(model), _key: model.key, _id: model._id } [ { name: nil, fromVertices: [fake_vertex], toVertices: [], edges: [], oldEdges: [] } ] end
prepare_edge_collection_for_transaction(ea)
click to toggle source
# File lib/guacamole/transaction.rb, line 133 def prepare_edge_collection_for_transaction(ea) TxEdgeCollection.new(ea, model).edge_collection_for_transaction end
read_collections()
click to toggle source
# File lib/guacamole/transaction.rb, line 145 def read_collections write_collections end
real_edge_collections()
click to toggle source
# File lib/guacamole/transaction.rb, line 103 def real_edge_collections @real_edge_collections ||= mapper.edge_attributes.each_with_object([]) do |ea, edge_collections| edge_collections << prepare_edge_collection_for_transaction(ea) end end
transaction_code()
click to toggle source
# File lib/guacamole/transaction.rb, line 161 def transaction_code File.read(Guacamole.configuration.shared_path.join('transaction.js')) end
transaction_params()
click to toggle source
# File lib/guacamole/transaction.rb, line 149 def transaction_params { edgeCollections: edge_collections, graph: Guacamole.configuration.graph.name, log_level: 'debug' } end
write_collections()
click to toggle source
# File lib/guacamole/transaction.rb, line 137 def write_collections edge_collections.map do |ec| [ec[:name]] + ec[:fromVertices].map { |fv| fv[:collection] } + ec[:toVertices].map { |tv| tv[:collection] } end.flatten.uniq.compact end
Private Instance Methods
transaction()
click to toggle source
# File lib/guacamole/transaction.rb, line 167 def transaction transaction = database.create_transaction(transaction_code, write: write_collections, read: read_collections) transaction.wait_for_sync = true transaction end