Class: Guacamole::Transaction::TxEdgeCollection
- Inherits:
-
Object
- Object
- Guacamole::Transaction::TxEdgeCollection
- Defined in:
- lib/guacamole/transaction.rb
Instance Attribute Summary collapse
-
#ea ⇒ Object
readonly
Returns the value of attribute ea.
-
#edge_collection ⇒ Object
readonly
Returns the value of attribute edge_collection.
-
#from_models ⇒ Object
readonly
Returns the value of attribute from_models.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#old_edges ⇒ Object
readonly
Returns the value of attribute old_edges.
-
#to_models ⇒ Object
readonly
Returns the value of attribute to_models.
Instance Method Summary collapse
- #edge_collection_for_transaction ⇒ Object
- #edges ⇒ Object
- #from_vertices ⇒ Object
- #init ⇒ Object
-
#initialize(ea, model) ⇒ TxEdgeCollection
constructor
A new instance of TxEdgeCollection.
- #select_mapper ⇒ Object
- #to_vertices ⇒ Object
- #to_vertices_with_only_existing_documents ⇒ Object
Constructor Details
#initialize(ea, model) ⇒ TxEdgeCollection
Returns a new instance of TxEdgeCollection.
15 16 17 18 19 20 21 |
# File 'lib/guacamole/transaction.rb', line 15 def initialize(ea, model) @ea = ea @model = model @edge_collection = EdgeCollection.for(ea.edge_class) init end |
Instance Attribute Details
#ea ⇒ Object (readonly)
Returns the value of attribute ea.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def ea @ea end |
#edge_collection ⇒ Object (readonly)
Returns the value of attribute edge_collection.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def edge_collection @edge_collection end |
#from_models ⇒ Object (readonly)
Returns the value of attribute from_models.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def from_models @from_models end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def model @model end |
#old_edges ⇒ Object (readonly)
Returns the value of attribute old_edges.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def old_edges @old_edges end |
#to_models ⇒ Object (readonly)
Returns the value of attribute to_models.
13 14 15 |
# File 'lib/guacamole/transaction.rb', line 13 def to_models @to_models end |
Instance Method Details
#edge_collection_for_transaction ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/guacamole/transaction.rb', line 82 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 ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/guacamole/transaction.rb', line 70 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 ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/guacamole/transaction.rb', line 42 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 ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/guacamole/transaction.rb', line 23 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 ⇒ Object
38 39 40 |
# File 'lib/guacamole/transaction.rb', line 38 def select_mapper ->(m) { edge_collection.mapper_for_start(m) } end |
#to_vertices ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/guacamole/transaction.rb', line 54 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 ⇒ Object
66 67 68 |
# File 'lib/guacamole/transaction.rb', line 66 def to_vertices_with_only_existing_documents to_vertices.select { |v| v[:_key].nil? } end |