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