Class: Guacamole::Transaction
- Inherits:
-
Object
- Object
- Guacamole::Transaction
show all
- Extended by:
- Forwardable
- Defined in:
- lib/guacamole/transaction.rb
Defined Under Namespace
Classes: TxEdgeCollection
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Transaction
Returns a new instance of Transaction.
99
100
101
102
|
# File 'lib/guacamole/transaction.rb', line 99
def initialize(options)
@collection = options[:collection]
@model = options[:model]
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
10
11
12
|
# File 'lib/guacamole/transaction.rb', line 10
def collection
@collection
end
|
#model ⇒ Object
Returns the value of attribute model.
10
11
12
|
# File 'lib/guacamole/transaction.rb', line 10
def model
@model
end
|
Class Method Details
.run(options) ⇒ Object
94
95
96
|
# File 'lib/guacamole/transaction.rb', line 94
def run(options)
new(options).execute_transaction
end
|
Instance Method Details
#edge_collections ⇒ Object
130
131
132
|
# File 'lib/guacamole/transaction.rb', line 130
def edge_collections
real_edge_collections.present? ? real_edge_collections : fake_edge_collections
end
|
#execute_transaction ⇒ Object
158
159
160
|
# File 'lib/guacamole/transaction.rb', line 158
def execute_transaction
transaction.execute(transaction_params)
end
|
#fake_edge_collections ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/guacamole/transaction.rb', line 110
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) ⇒ Object
#read_collections ⇒ Object
146
147
148
|
# File 'lib/guacamole/transaction.rb', line 146
def read_collections
write_collections
end
|
#real_edge_collections ⇒ Object
104
105
106
107
108
|
# File 'lib/guacamole/transaction.rb', line 104
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 ⇒ Object
#transaction_params ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/guacamole/transaction.rb', line 150
def transaction_params
{
edgeCollections: edge_collections,
graph: Guacamole.configuration.graph.name,
log_level: 'debug'
}
end
|
#write_collections ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/guacamole/transaction.rb', line 138
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
|