arangorb 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ArangoRB.gemspec +18 -18
  3. data/Gemfile +8 -7
  4. data/LICENSE +21 -21
  5. data/README.md +906 -867
  6. data/lib/ArangoRB_AQL.rb +181 -160
  7. data/lib/ArangoRB_Cache.rb +174 -174
  8. data/lib/ArangoRB_Col.rb +526 -499
  9. data/lib/ArangoRB_DB.rb +363 -339
  10. data/lib/ArangoRB_Doc.rb +319 -298
  11. data/lib/ArangoRB_Edg.rb +184 -169
  12. data/lib/ArangoRB_Gra.rb +201 -180
  13. data/lib/ArangoRB_Index.rb +135 -115
  14. data/lib/ArangoRB_Replication.rb +261 -0
  15. data/lib/ArangoRB_Ser.rb +446 -441
  16. data/lib/ArangoRB_Task.rb +129 -113
  17. data/lib/ArangoRB_Tra.rb +169 -142
  18. data/lib/ArangoRB_Tran.rb +68 -53
  19. data/lib/ArangoRB_User.rb +149 -136
  20. data/lib/ArangoRB_Ver.rb +162 -147
  21. data/lib/arangorb.rb +16 -15
  22. data/spec/arangoRB_helper.rb +4 -4
  23. data/spec/arangoRestart_helper.rb +14 -14
  24. data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
  25. data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
  26. data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
  27. data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
  28. data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
  29. data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
  30. data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
  31. data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
  32. data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
  33. data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
  34. data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
  35. data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
  36. data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
  37. data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
  38. data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
  39. data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
  40. data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
  41. data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
  42. data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
  43. data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
  44. data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
  45. data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
  46. data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
  47. data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
  48. data/spec/spec_helper.rb +41 -41
  49. metadata +6 -5
@@ -1,298 +1,319 @@
1
- # ==== DOCUMENT ====
2
-
3
- class ArangoDocument < ArangoServer
4
- def initialize(key: nil, collection: @@collection, database: @@database, body: {}, from: nil, to: nil) # TESTED
5
- if collection.is_a?(String)
6
- @collection = collection
7
- elsif collection.is_a?(ArangoCollection)
8
- @collection = collection.collection
9
- else
10
- raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
11
- end
12
-
13
- if database.is_a?(String)
14
- @database = database
15
- elsif database.is_a?(ArangoDatabase)
16
- @database = database.database
17
- else
18
- raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
19
- end
20
-
21
- if key.is_a?(String) || key.nil?
22
- @key = key
23
- unless key.nil?
24
- body["_key"] = @key
25
- @id = "#{@collection}/#{@key}"
26
- end
27
- elsif key.is_a?(ArangoDocument)
28
- @key = key.key
29
- @id = key.id
30
- else
31
- raise "key should be a String, not a #{key.class}"
32
- end
33
-
34
- if body.is_a?(Hash)
35
- @body = body
36
- else
37
- raise "body should be a Hash, not a #{body.class}"
38
- end
39
-
40
- if from.is_a?(String)
41
- @body["_from"] = from
42
- elsif from.is_a?(ArangoDocument)
43
- @body["_from"] = from.id
44
- elsif from.nil?
45
- else
46
- raise "from should be a String or an ArangoDocument instance, not a #{from.class}"
47
- end
48
-
49
- if to.is_a?(String)
50
- @body["_to"] = to
51
- elsif to.is_a?(ArangoDocument)
52
- @body["_to"] = to.id
53
- elsif to.nil?
54
- else
55
- raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
56
- end
57
-
58
- @idCache = "DOC_#{@id}"
59
- end
60
-
61
- attr_reader :key, :id, :body, :idCache
62
- alias name key
63
-
64
- # === RETRIEVE ===
65
-
66
- def collection
67
- ArangoCollection.new(collection: @collection, database: @database)
68
- end
69
-
70
- def database
71
- ArangoDatabase.new(database: @database)
72
- end
73
-
74
- # === GET ===
75
-
76
- def retrieve # TESTED
77
- result = self.class.get("/_db/#{@database}/_api/document/#{@id}", @@request)
78
- self.return_result result: result
79
- end
80
-
81
- def retrieve_edges(collection: , direction: nil) # TESTED
82
- query = {"vertex" => @id, "direction" => direction }.delete_if{|k,v| v.nil?}
83
- request = @@request.merge({ :query => query })
84
- collection = collection.is_a?(String) ? collection : collection.collection
85
- result = self.class.get("/_db/#{@database}/_api/edges/#{collection}", request)
86
- return result.headers["x-arango-async-id"] if @@async == "store"
87
- result = result.parsed_response
88
- @@verbose ? result : result["error"] ? result["errorMessage"] : result["edges"].map{|edge| ArangoDocument.new(key: edge["_key"], collection: collection, database: @database, body: edge)}
89
- end
90
-
91
- def in(edgeCollection) # TESTED
92
- self.retrieve_edges collection: edgeCollection, direction: "in"
93
- end
94
-
95
- def out(edgeCollection) # TESTED
96
- self.retrieve_edges collection: edgeCollection, direction: "out"
97
- end
98
-
99
- def any(edgeCollection) # TESTED
100
- self.retrieve_edges collection: edgeCollection
101
- end
102
-
103
- def from # TESTED
104
- result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_from"]}", @@request)
105
- collection = result["_id"].split("/")[0]
106
- return result.headers["x-arango-async-id"] if @@async == "store"
107
- result = result.parsed_response
108
- @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
109
- end
110
-
111
- def to # TESTED
112
- result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_to"]}", @@request)
113
- collection = result["_id"].split("/")[0]
114
- return result.headers["x-arango-async-id"] if @@async == "store"
115
- result = result.parsed_response
116
- @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
117
- end
118
-
119
- # def header
120
- # result = self.class.head("/_db/#{@database}/_api/document/#{@id}", follow_redirects: true, maintain_method_across_redirects: true)
121
- # @@verbose ? result : result["error"] ? result["errorMessage"] : result
122
- # end
123
-
124
- # === POST ====
125
-
126
- def create(body: {}, waitForSync: nil, returnNew: nil) # TESTED
127
- body = @body.merge(body)
128
- query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
129
- body["_key"] = @key if body["_key"].nil? && !key.nil?
130
- request = @@request.merge({ :body => @body.to_json, :query => query })
131
- result = self.class.post("/_db/#{@database}/_api/document/#{@collection}", request)
132
- return_result result: result, body: @body
133
- end
134
- alias create_document create
135
- alias create_vertex create
136
-
137
- def self.create(body: {}, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
138
- collection = collection.is_a?(String) ? collection : collection.collection
139
- database = database.is_a?(String) ? database : database.database
140
- query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
141
- unless body.is_a? Array
142
- request = @@request.merge({ :body => body.to_json, :query => query })
143
- result = post("/_db/#{database}/_api/document/#{collection}", request)
144
- return result.headers["x-arango-async-id"] if @@async == "store"
145
- result = result.parsed_response
146
- @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: result["_id"].split("/")[0], body: body)
147
- else
148
- body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
149
- request = @@request.merge({ :body => body.to_json, :query => query })
150
- result = post("/_db/#{database}/_api/document/#{collection}", request)
151
- i = -1
152
- return result.headers["x-arango-async-id"] if @@async == "store"
153
- result = result.parsed_response
154
- @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
155
- end
156
- end
157
-
158
- def create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @database, collection: @collection) # TESTED
159
- body = @body.merge(body)
160
- edges = []
161
- from = [from] unless from.is_a? Array
162
- to = [to] unless to.is_a? Array
163
- from.each do |f|
164
- body["_from"] = f.is_a?(String) ? f : f.id
165
- to.each do |t|
166
- body["_to"] = t.is_a?(String) ? t : t.id
167
- edges << body.clone
168
- end
169
- end
170
- edges = edges[0]
171
- ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
172
- end
173
-
174
- def self.create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
175
- edges = []
176
- from = [from] unless from.is_a? Array
177
- to = [to] unless to.is_a? Array
178
- body = [body] unless body.is_a? Array
179
- body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
180
- body.each do |b|
181
- from.each do |f|
182
- b["_from"] = f.is_a?(String) ? f : f.id
183
- to.each do |t|
184
- b["_to"] = t.is_a?(String) ? t : t.id
185
- edges << b.clone
186
- end
187
- end
188
- end
189
- edges = edges[0] if edges.length == 1
190
- ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
191
- end
192
-
193
- # === MODIFY ===
194
-
195
- def replace(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) # TESTED
196
- query = {
197
- "waitForSync" => waitForSync,
198
- "returnNew" => returnNew,
199
- "returnOld" => returnOld,
200
- "ignoreRevs" => ignoreRevs
201
- }.delete_if{|k,v| v.nil?}
202
- request = @@request.merge({ :body => body.to_json, :query => query })
203
-
204
- unless body.is_a? Array
205
- result = self.class.put("/_db/#{@database}/_api/document/#{@id}", request)
206
- self.return_result result: result, body: body
207
- else
208
- result = self.class.put("/_db/#{@database}/_api/document/#{@collection}", request)
209
- i = -1
210
- return result.headers["x-arango-async-id"] if @@async == "store"
211
- result = result.parsed_response
212
- @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
213
- end
214
- end
215
-
216
- def update(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) # TESTED
217
- query = {
218
- "waitForSync" => waitForSync,
219
- "returnNew" => returnNew,
220
- "returnOld" => returnOld,
221
- "ignoreRevs" => ignoreRevs,
222
- "keepNull" => keepNull,
223
- "mergeObjects" => mergeObjects
224
- }.delete_if{|k,v| v.nil?}
225
- request = @@request.merge({ :body => body.to_json, :query => query })
226
-
227
- unless body.is_a? Array
228
- result = self.class.patch("/_db/#{@database}/_api/document/#{@id}", request)
229
- return result.headers["x-arango-async-id"] if @@async == "store"
230
- result = result.parsed_response
231
- if @@verbose
232
- unless result["error"]
233
- @key = result["_key"]
234
- @id = "#{@collection}/#{@key}"
235
- @body = body
236
- end
237
- result
238
- else
239
- return result["errorMessage"] if result["error"]
240
- @key = result["_key"]
241
- @id = "#{@collection}/#{@key}"
242
- @body = @body.merge(body)
243
- return self
244
- end
245
- else
246
- result = self.class.patch("/_db/#{@database}/_api/document/#{@collection}", request)
247
- i = -1
248
- return result.headers["x-arango-async-id"] if @@async == "store"
249
- result = result.parsed_response
250
- @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
251
- end
252
- end
253
-
254
- # === DELETE ===
255
-
256
- def destroy(body: nil, waitForSync: nil, ignoreRevs: nil, returnOld: nil) # TESTED
257
- query = {
258
- "waitForSync" => waitForSync,
259
- "returnOld" => returnOld,
260
- "ignoreRevs" => ignoreRevs
261
- }.delete_if{|k,v| v.nil?}
262
- request = @@request.merge({ :body => body.to_json, :query => query })
263
-
264
- unless body.is_a? Array
265
- result = self.class.delete("/_db/#{@database}/_api/document/#{@id}", request)
266
- return_result result: result, caseTrue: true
267
- else
268
- result = self.class.delete("/_db/#{@database}/_api/document/#{@collection}", request)
269
- return_result result: result, caseTrue: true
270
- end
271
- end
272
-
273
- # === UTILITY ===
274
-
275
- def return_result(result:, body: {}, caseTrue: false, key: nil)
276
- return result.headers["x-arango-async-id"] if @@async == "store"
277
- result = result.parsed_response
278
- if @@verbose || !result.is_a?(Hash)
279
- resultTemp = result
280
- unless result["errorMessage"]
281
- result.delete_if{|k,v| k == "error" || k == "code"}
282
- @key = result["_key"]
283
- @collection = result["_id"].split("/")[0]
284
- @body = result.merge(body)
285
- end
286
- return resultTemp
287
- else
288
- return result["errorMessage"] if result["error"]
289
- return true if caseTrue
290
- result.delete_if{|k,v| k == "error" || k == "code"}
291
- @key = result["_key"]
292
- @collection = result["_id"].split("/")[0]
293
- @id = "#{@collection}/#{@key}"
294
- @body = result.merge(body)
295
- key.nil? ? self : result[key]
296
- end
297
- end
298
- end
1
+ # ==== DOCUMENT ====
2
+
3
+ class ArangoDocument < ArangoServer
4
+ def initialize(key: nil, collection: @@collection, database: @@database, body: {}, from: nil, to: nil) # TESTED
5
+ if collection.is_a?(String)
6
+ @collection = collection
7
+ elsif collection.is_a?(ArangoCollection)
8
+ @collection = collection.collection
9
+ else
10
+ raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
11
+ end
12
+
13
+ if database.is_a?(String)
14
+ @database = database
15
+ elsif database.is_a?(ArangoDatabase)
16
+ @database = database.database
17
+ else
18
+ raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
19
+ end
20
+
21
+ if key.is_a?(String) || key.nil?
22
+ @key = key
23
+ unless key.nil?
24
+ body["_key"] = @key
25
+ @id = "#{@collection}/#{@key}"
26
+ end
27
+ elsif key.is_a?(ArangoDocument)
28
+ @key = key.key
29
+ @id = key.id
30
+ else
31
+ raise "key should be a String, not a #{key.class}"
32
+ end
33
+
34
+ if body.is_a?(Hash)
35
+ @body = body
36
+ else
37
+ raise "body should be a Hash, not a #{body.class}"
38
+ end
39
+
40
+ if from.is_a?(String)
41
+ @body["_from"] = from
42
+ elsif from.is_a?(ArangoDocument)
43
+ @body["_from"] = from.id
44
+ elsif from.nil?
45
+ else
46
+ raise "from should be a String or an ArangoDocument instance, not a #{from.class}"
47
+ end
48
+
49
+ if to.is_a?(String)
50
+ @body["_to"] = to
51
+ elsif to.is_a?(ArangoDocument)
52
+ @body["_to"] = to.id
53
+ elsif to.nil?
54
+ else
55
+ raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
56
+ end
57
+
58
+ @idCache = "DOC_#{@id}"
59
+ end
60
+
61
+ attr_reader :key, :id, :body, :idCache
62
+ alias name key
63
+
64
+ # === RETRIEVE ===
65
+
66
+ def to_hash
67
+ {
68
+ "key" => @key,
69
+ "id" => @id,
70
+ "collection" => @collection,
71
+ "database" => @database,
72
+ "body" => @body,
73
+ "idCache" => @idCache
74
+ }.delete_if{|k,v| v.nil?}
75
+ end
76
+ alias to_h to_hash
77
+
78
+ def collection
79
+ ArangoCollection.new(collection: @collection, database: @database)
80
+ end
81
+
82
+ def database
83
+ ArangoDatabase.new(database: @database)
84
+ end
85
+
86
+ # === GET ===
87
+
88
+ def retrieve # TESTED
89
+ result = self.class.get("/_db/#{@database}/_api/document/#{@id}", @@request)
90
+ self.return_result result: result
91
+ end
92
+
93
+ def retrieve_edges(collection: , direction: nil) # TESTED
94
+ query = {"vertex" => @id, "direction" => direction }.delete_if{|k,v| v.nil?}
95
+ request = @@request.merge({ :query => query })
96
+ collection = collection.is_a?(String) ? collection : collection.collection
97
+ result = self.class.get("/_db/#{@database}/_api/edges/#{collection}", request)
98
+ return result.headers["x-arango-async-id"] if @@async == "store"
99
+ return true if @@async
100
+ result = result.parsed_response
101
+ @@verbose ? result : result["error"] ? result["errorMessage"] : result["edges"].map{|edge| ArangoDocument.new(key: edge["_key"], collection: collection, database: @database, body: edge)}
102
+ end
103
+
104
+ def in(edgeCollection) # TESTED
105
+ self.retrieve_edges collection: edgeCollection, direction: "in"
106
+ end
107
+
108
+ def out(edgeCollection) # TESTED
109
+ self.retrieve_edges collection: edgeCollection, direction: "out"
110
+ end
111
+
112
+ def any(edgeCollection) # TESTED
113
+ self.retrieve_edges collection: edgeCollection
114
+ end
115
+
116
+ def from # TESTED
117
+ result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_from"]}", @@request)
118
+ collection = result["_id"].split("/")[0]
119
+ return result.headers["x-arango-async-id"] if @@async == "store"
120
+ return true if @@async
121
+ result = result.parsed_response
122
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
123
+ end
124
+
125
+ def to # TESTED
126
+ result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_to"]}", @@request)
127
+ collection = result["_id"].split("/")[0]
128
+ return result.headers["x-arango-async-id"] if @@async == "store"
129
+ return true if @@async
130
+ result = result.parsed_response
131
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
132
+ end
133
+
134
+ # def header
135
+ # result = self.class.head("/_db/#{@database}/_api/document/#{@id}", follow_redirects: true, maintain_method_across_redirects: true)
136
+ # @@verbose ? result : result["error"] ? result["errorMessage"] : result
137
+ # end
138
+
139
+ # === POST ====
140
+
141
+ def create(body: {}, waitForSync: nil, returnNew: nil) # TESTED
142
+ body = @body.merge(body)
143
+ query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
144
+ body["_key"] = @key if body["_key"].nil? && !key.nil?
145
+ request = @@request.merge({ :body => @body.to_json, :query => query })
146
+ result = self.class.post("/_db/#{@database}/_api/document/#{@collection}", request)
147
+ return_result result: result, body: @body
148
+ end
149
+ alias create_document create
150
+ alias create_vertex create
151
+
152
+ def self.create(body: {}, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
153
+ collection = collection.is_a?(String) ? collection : collection.collection
154
+ database = database.is_a?(String) ? database : database.database
155
+ query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
156
+ unless body.is_a? Array
157
+ request = @@request.merge({ :body => body.to_json, :query => query })
158
+ result = post("/_db/#{database}/_api/document/#{collection}", request)
159
+ return result.headers["x-arango-async-id"] if @@async == "store"
160
+ return true if @@async
161
+ result = result.parsed_response
162
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: result["_id"].split("/")[0], body: body)
163
+ else
164
+ body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
165
+ request = @@request.merge({ :body => body.to_json, :query => query })
166
+ result = post("/_db/#{database}/_api/document/#{collection}", request)
167
+ return result.headers["x-arango-async-id"] if @@async == "store"
168
+ return true if @@async
169
+ result = result.parsed_response
170
+ i = -1
171
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
172
+ end
173
+ end
174
+
175
+ def create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @database, collection: @collection) # TESTED
176
+ body = @body.merge(body)
177
+ edges = []
178
+ from = [from] unless from.is_a? Array
179
+ to = [to] unless to.is_a? Array
180
+ from.each do |f|
181
+ body["_from"] = f.is_a?(String) ? f : f.id
182
+ to.each do |t|
183
+ body["_to"] = t.is_a?(String) ? t : t.id
184
+ edges << body.clone
185
+ end
186
+ end
187
+ edges = edges[0]
188
+ ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
189
+ end
190
+
191
+ def self.create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
192
+ edges = []
193
+ from = [from] unless from.is_a? Array
194
+ to = [to] unless to.is_a? Array
195
+ body = [body] unless body.is_a? Array
196
+ body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
197
+ body.each do |b|
198
+ from.each do |f|
199
+ b["_from"] = f.is_a?(String) ? f : f.id
200
+ to.each do |t|
201
+ b["_to"] = t.is_a?(String) ? t : t.id
202
+ edges << b.clone
203
+ end
204
+ end
205
+ end
206
+ edges = edges[0] if edges.length == 1
207
+ ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
208
+ end
209
+
210
+ # === MODIFY ===
211
+
212
+ def replace(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) # TESTED
213
+ query = {
214
+ "waitForSync" => waitForSync,
215
+ "returnNew" => returnNew,
216
+ "returnOld" => returnOld,
217
+ "ignoreRevs" => ignoreRevs
218
+ }.delete_if{|k,v| v.nil?}
219
+ request = @@request.merge({ :body => body.to_json, :query => query })
220
+
221
+ unless body.is_a? Array
222
+ result = self.class.put("/_db/#{@database}/_api/document/#{@id}", request)
223
+ self.return_result result: result, body: body
224
+ else
225
+ result = self.class.put("/_db/#{@database}/_api/document/#{@collection}", request)
226
+ i = -1
227
+ return result.headers["x-arango-async-id"] if @@async == "store"
228
+ return true if @@async
229
+ result = result.parsed_response
230
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
231
+ end
232
+ end
233
+
234
+ def update(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) # TESTED
235
+ query = {
236
+ "waitForSync" => waitForSync,
237
+ "returnNew" => returnNew,
238
+ "returnOld" => returnOld,
239
+ "ignoreRevs" => ignoreRevs,
240
+ "keepNull" => keepNull,
241
+ "mergeObjects" => mergeObjects
242
+ }.delete_if{|k,v| v.nil?}
243
+ request = @@request.merge({ :body => body.to_json, :query => query })
244
+
245
+ unless body.is_a? Array
246
+ result = self.class.patch("/_db/#{@database}/_api/document/#{@id}", request)
247
+ return result.headers["x-arango-async-id"] if @@async == "store"
248
+ return true if @@async
249
+ result = result.parsed_response
250
+ if @@verbose
251
+ unless result["error"]
252
+ @key = result["_key"]
253
+ @id = "#{@collection}/#{@key}"
254
+ @body = body
255
+ end
256
+ result
257
+ else
258
+ return result["errorMessage"] if result["error"]
259
+ @key = result["_key"]
260
+ @id = "#{@collection}/#{@key}"
261
+ @body = @body.merge(body)
262
+ return self
263
+ end
264
+ else
265
+ result = self.class.patch("/_db/#{@database}/_api/document/#{@collection}", request)
266
+ i = -1
267
+ return result.headers["x-arango-async-id"] if @@async == "store"
268
+ return true if @@async
269
+ result = result.parsed_response
270
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
271
+ end
272
+ end
273
+
274
+ # === DELETE ===
275
+
276
+ def destroy(body: nil, waitForSync: nil, ignoreRevs: nil, returnOld: nil) # TESTED
277
+ query = {
278
+ "waitForSync" => waitForSync,
279
+ "returnOld" => returnOld,
280
+ "ignoreRevs" => ignoreRevs
281
+ }.delete_if{|k,v| v.nil?}
282
+ request = @@request.merge({ :body => body.to_json, :query => query })
283
+
284
+ unless body.is_a? Array
285
+ result = self.class.delete("/_db/#{@database}/_api/document/#{@id}", request)
286
+ return_result result: result, caseTrue: true
287
+ else
288
+ result = self.class.delete("/_db/#{@database}/_api/document/#{@collection}", request)
289
+ return_result result: result, caseTrue: true
290
+ end
291
+ end
292
+
293
+ # === UTILITY ===
294
+
295
+ def return_result(result:, body: {}, caseTrue: false, key: nil)
296
+ return result.headers["x-arango-async-id"] if @@async == "store"
297
+ return true if @@async
298
+ result = result.parsed_response
299
+ if @@verbose || !result.is_a?(Hash)
300
+ resultTemp = result
301
+ unless result["errorMessage"]
302
+ result.delete_if{|k,v| k == "error" || k == "code"}
303
+ @key = result["_key"]
304
+ @collection = result["_id"].split("/")[0]
305
+ @body = result.merge(body)
306
+ end
307
+ return resultTemp
308
+ else
309
+ return result["errorMessage"] if result["error"]
310
+ return true if caseTrue
311
+ result.delete_if{|k,v| k == "error" || k == "code"}
312
+ @key = result["_key"]
313
+ @collection = result["_id"].split("/")[0]
314
+ @id = "#{@collection}/#{@key}"
315
+ @body = result.merge(body)
316
+ key.nil? ? self : result[key]
317
+ end
318
+ end
319
+ end