arangorb 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +18 -18
- data/Gemfile +8 -7
- data/LICENSE +21 -21
- data/README.md +906 -867
- data/lib/ArangoRB_AQL.rb +181 -160
- data/lib/ArangoRB_Cache.rb +174 -174
- data/lib/ArangoRB_Col.rb +526 -499
- data/lib/ArangoRB_DB.rb +363 -339
- data/lib/ArangoRB_Doc.rb +319 -298
- data/lib/ArangoRB_Edg.rb +184 -169
- data/lib/ArangoRB_Gra.rb +201 -180
- data/lib/ArangoRB_Index.rb +135 -115
- data/lib/ArangoRB_Replication.rb +261 -0
- data/lib/ArangoRB_Ser.rb +446 -441
- data/lib/ArangoRB_Task.rb +129 -113
- data/lib/ArangoRB_Tra.rb +169 -142
- data/lib/ArangoRB_Tran.rb +68 -53
- data/lib/ArangoRB_User.rb +149 -136
- data/lib/ArangoRB_Ver.rb +162 -147
- data/lib/arangorb.rb +16 -15
- data/spec/arangoRB_helper.rb +4 -4
- data/spec/arangoRestart_helper.rb +14 -14
- data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
- data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
- data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
- data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
- data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
- data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
- data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
- data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
- data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
- data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
- data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
- data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
- data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
- data/spec/spec_helper.rb +41 -41
- metadata +6 -5
data/lib/ArangoRB_Doc.rb
CHANGED
@@ -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
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
collection
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
collection
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
result
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
body
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
"
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
result
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
result = self.class.patch("/_db/#{@database}/_api/document/#{@
|
247
|
-
|
248
|
-
return
|
249
|
-
result = result.parsed_response
|
250
|
-
@@verbose
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
result = self.class.
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
else
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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
|