arangorb 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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_Tra.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# === TRAVERSAL ===
|
2
2
|
|
3
|
-
class
|
4
|
-
def initialize(body: {}, database: @@database, graph: nil, edgeCollection: nil)
|
3
|
+
class ArangoTraversal < ArangoServer
|
4
|
+
def initialize(body: {}, database: @@database, graph: nil, edgeCollection: nil) # TESTED
|
5
5
|
@sort = body["sort"]
|
6
6
|
@direction = body["direction"]
|
7
7
|
@maxDepth = body["maxDepth"]
|
@@ -26,45 +26,45 @@ class ArangoT < ArangoS
|
|
26
26
|
attr_accessor :sort, :direction, :maxDepth, :minDepth, :visitor, :itemOrder, :strategy, :filter, :init, :maxiterations, :uniqueness, :order, :expander, :vertices, :paths, :database
|
27
27
|
attr_reader :startVertex, :graphName, :edgeCollection
|
28
28
|
|
29
|
-
def startVertex=(startVertex)
|
29
|
+
def startVertex=(startVertex) # TESTED
|
30
30
|
if startVertex.is_a?(String)
|
31
31
|
@startVertex = startVertex
|
32
|
-
elsif startVertex.is_a?(
|
32
|
+
elsif startVertex.is_a?(ArangoDocument)
|
33
33
|
@startVertex = startVertex.id
|
34
34
|
else
|
35
|
-
raise "startVertex should be a String or an
|
35
|
+
raise "startVertex should be a String or an ArangoDocument instance, not a #{startVertex.class}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def graphName=(graphName)
|
39
|
+
def graphName=(graphName) # TESTED
|
40
40
|
if graphName.is_a?(String) || graphName.nil?
|
41
41
|
@graphName = graphName
|
42
|
-
elsif graphName.is_a?(
|
42
|
+
elsif graphName.is_a?(ArangoGraph)
|
43
43
|
@graphName = graphName.graph
|
44
44
|
else
|
45
|
-
raise "graphName should be a String or an
|
45
|
+
raise "graphName should be a String or an ArangoGraph instance, not a #{graphName.class}"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def edgeCollection=(edgeCollection)
|
49
|
+
def edgeCollection=(edgeCollection) # TESTED
|
50
50
|
if edgeCollection.is_a?(String) || edgeCollection.nil?
|
51
51
|
@edgeCollection = edgeCollection
|
52
|
-
elsif edgeCollection.is_a?(
|
52
|
+
elsif edgeCollection.is_a?(ArangoCollection)
|
53
53
|
@edgeCollection = edgeCollection.collection
|
54
54
|
else
|
55
|
-
raise "edgeCollection should be a String or an
|
55
|
+
raise "edgeCollection should be a String or an ArangoCollection instance, not a #{edgeCollection.class}"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def in
|
59
|
+
def in # TESTED
|
60
60
|
@direction = "inbound"
|
61
61
|
end
|
62
62
|
|
63
|
-
def out
|
63
|
+
def out # TESTED
|
64
64
|
@direction = "outbound"
|
65
65
|
end
|
66
66
|
|
67
|
-
def any
|
67
|
+
def any # TESTED
|
68
68
|
@direction = "any"
|
69
69
|
end
|
70
70
|
|
@@ -79,7 +79,7 @@ class ArangoT < ArangoS
|
|
79
79
|
alias graph graphName
|
80
80
|
alias graph= graphName=
|
81
81
|
|
82
|
-
def execute
|
82
|
+
def execute # TESTED
|
83
83
|
body = {
|
84
84
|
"sort" => @sort,
|
85
85
|
"direction" => @direction,
|
@@ -98,35 +98,40 @@ class ArangoT < ArangoS
|
|
98
98
|
"expander" => @expander,
|
99
99
|
"edgeCollection" => @edgeCollection
|
100
100
|
}.delete_if{|k,v| v.nil?}
|
101
|
-
|
102
|
-
result = self.class.post("/_db/#{@database}/_api/traversal",
|
103
|
-
if
|
104
|
-
|
101
|
+
request = @@request.merge({ :body => body.to_json })
|
102
|
+
result = self.class.post("/_db/#{@database}/_api/traversal", request)
|
103
|
+
if @@async == "store"
|
104
|
+
result.headers["x-arango-async-id"]
|
105
105
|
else
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
106
|
+
result = result.parsed_response
|
107
|
+
if result["error"]
|
108
|
+
return @@verbose ? result : result["errorMessage"]
|
109
|
+
else
|
110
|
+
@vertices = result["result"]["visited"]["vertices"].map{|x| ArangoDocument.new(
|
111
|
+
key: x["_key"],
|
112
|
+
collection: x["_id"].split("/")[0],
|
113
|
+
database: @database,
|
114
|
+
body: x
|
115
|
+
)}
|
116
|
+
@paths = result["result"]["visited"]["paths"].map{|x|
|
117
|
+
{ "edges" => x["edges"].map{|e| ArangoDocument.new(
|
118
|
+
key: e["_key"],
|
119
|
+
collection: e["_id"].split("/")[0],
|
120
|
+
database: @database,
|
121
|
+
body: e,
|
122
|
+
from: e["_from"],
|
123
|
+
to: e["_to"]
|
124
|
+
)},
|
125
|
+
"vertices" => x["vertices"].map{|v| ArangoDocument.new(
|
126
|
+
key: v["_key"],
|
127
|
+
collection: v["_id"].split("/")[0],
|
128
|
+
database: @database,
|
129
|
+
body: v
|
130
|
+
)}
|
131
|
+
}
|
127
132
|
}
|
128
|
-
|
129
|
-
|
133
|
+
return @@verbose ? result : self
|
134
|
+
end
|
130
135
|
end
|
131
136
|
end
|
132
137
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# === TRANSACTION ===
|
2
|
+
|
3
|
+
class ArangoTransaction < ArangoServer
|
4
|
+
def initialize(database: @@database, action:, write: [], read: [], params: nil, lockTimeout: nil, waitForSync: nil) # TESTED
|
5
|
+
if database.is_a?(String)
|
6
|
+
@database = database
|
7
|
+
elsif database.is_a?(ArangoDatabase)
|
8
|
+
@database = database.database
|
9
|
+
else
|
10
|
+
raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
|
11
|
+
end
|
12
|
+
@action = action
|
13
|
+
@collections = {}
|
14
|
+
@collections["write"] = write.is_a?(Array) ? write.map{ |x| x.is_a?(String) ? x : x.is_a?(ArangoCollection) ? x.collection : nil } : write.is_a?(String) ? [write] : write.is_a?(ArangoCollection) ? [write.collection] : []
|
15
|
+
@collections["read"] = read.is_a?(Array) ? read.map{ |x| x.is_a?(String) ? x : x.is_a?(ArangoCollection) ? x.collection : nil } : read.is_a?(String) ? [read] : read.is_a?(ArangoCollection) ? [read.collection] : []
|
16
|
+
@params = params
|
17
|
+
@lockTimeout = lockTimeout
|
18
|
+
@waitForSync = waitForSync
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :action, :collections, :params, :lockTimeout, :waitForSync
|
22
|
+
|
23
|
+
def execute # TESTED
|
24
|
+
body = {
|
25
|
+
"action" => @action,
|
26
|
+
"collections" => @collections,
|
27
|
+
"params" => @params,
|
28
|
+
"lockTimeout" => @lockTimeout,
|
29
|
+
"waitForSync" => @waitForSync
|
30
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
31
|
+
request = @@request.merge({ :body => body })
|
32
|
+
result = self.class.post("/_db/#{@database}/_api/transaction", request)
|
33
|
+
if @@async == "store"
|
34
|
+
result.headers["x-arango-async-id"]
|
35
|
+
else
|
36
|
+
result = result.parsed_response
|
37
|
+
if @@verbose
|
38
|
+
result
|
39
|
+
else
|
40
|
+
if result["error"]
|
41
|
+
{"message": result["errorMessage"], "stacktrace": result["stacktrace"]}
|
42
|
+
else
|
43
|
+
result["result"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# === USER ===
|
2
|
+
|
3
|
+
class ArangoUser < ArangoServer
|
4
|
+
def initialize(user: @@user, password: nil, active: nil, extra: nil) # TESTED
|
5
|
+
@password = password
|
6
|
+
@user = user
|
7
|
+
@active = active
|
8
|
+
@extra = extra
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :user, :active, :extra
|
12
|
+
|
13
|
+
def create(active: nil, extra: nil) # TESTED
|
14
|
+
body = {
|
15
|
+
"user" => @user,
|
16
|
+
"passwd" => @password,
|
17
|
+
"active" => active,
|
18
|
+
"extra" => extra
|
19
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
20
|
+
request = @@request.merge({ :body => body })
|
21
|
+
result = self.class.post("/_api/user", request)
|
22
|
+
resultTemp = result.parsed_response
|
23
|
+
if @@async != "store" && !resultTemp["error"]
|
24
|
+
@active = resultTemp["active"]
|
25
|
+
@extra = resultTemp["extra"]
|
26
|
+
end
|
27
|
+
return_result result: result
|
28
|
+
end
|
29
|
+
|
30
|
+
def retrieve # TESTED
|
31
|
+
result = self.class.get("/_api/user/#{@user}", @@request)
|
32
|
+
resultTemp = result.parsed_response
|
33
|
+
if @@async != "store" && !resultTemp["error"]
|
34
|
+
@active = resultTemp["active"]
|
35
|
+
@extra = resultTemp["extra"]
|
36
|
+
end
|
37
|
+
return_result result: result
|
38
|
+
end
|
39
|
+
|
40
|
+
def grant(database: @@database) # TESTED
|
41
|
+
database = database.database if database.is_a?(ArangoDatabase)
|
42
|
+
body = { "grant" => "rw" }.to_json
|
43
|
+
request = @@request.merge({ :body => body })
|
44
|
+
result = self.class.put("/_api/user/#{@user}/database/#{database}", request)
|
45
|
+
return_result result: result, caseTrue: true
|
46
|
+
end
|
47
|
+
|
48
|
+
def revoke(database: @@database) # TESTED
|
49
|
+
database = database.database if database.is_a?(ArangoDatabase)
|
50
|
+
body = { "grant" => "none" }.to_json
|
51
|
+
request = @@request.merge({ :body => body })
|
52
|
+
result = self.class.put("/_api/user/#{@user}/database/#{database}", request)
|
53
|
+
return_result result: result, caseTrue: true
|
54
|
+
end
|
55
|
+
|
56
|
+
def databases # TESTED
|
57
|
+
result = self.class.get("/_api/user/#{@user}/database/", @@request)
|
58
|
+
return_result result: result, key: "result"
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace(password:, active: nil, extra: nil) # TESTED
|
62
|
+
body = {
|
63
|
+
"passwd" => password,
|
64
|
+
"active" => active,
|
65
|
+
"extra" => extra
|
66
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
67
|
+
request = @@request.merge({ :body => body })
|
68
|
+
result = self.class.put("/_api/user/#{@user}", request)
|
69
|
+
if @@async == "store"
|
70
|
+
result.headers["x-arango-async-id"]
|
71
|
+
else
|
72
|
+
result = result.parsed_response
|
73
|
+
if @@verbose
|
74
|
+
unless result["error"]
|
75
|
+
@password = password
|
76
|
+
@active = active.nil? || active
|
77
|
+
@extra = extra
|
78
|
+
end
|
79
|
+
result
|
80
|
+
else
|
81
|
+
if result["error"]
|
82
|
+
result["errorMessage"]
|
83
|
+
else
|
84
|
+
@password = password
|
85
|
+
@active = active.nil? || active
|
86
|
+
@extra = extra
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def update(password: , active: nil, extra: nil) # TESTED
|
94
|
+
body = {
|
95
|
+
"passwd" => password,
|
96
|
+
"active" => active,
|
97
|
+
"extra" => extra
|
98
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
99
|
+
request = @@request.merge({ :body => body })
|
100
|
+
result = self.class.patch("/_api/user/#{@user}", request)
|
101
|
+
if @@async == "store"
|
102
|
+
result.headers["x-arango-async-id"]
|
103
|
+
else
|
104
|
+
result = result.parsed_response
|
105
|
+
if @@verbose
|
106
|
+
unless result["error"]
|
107
|
+
@password = password
|
108
|
+
@active = active.nil? || active
|
109
|
+
@extra = extra
|
110
|
+
end
|
111
|
+
result
|
112
|
+
else
|
113
|
+
if result["error"]
|
114
|
+
result["errorMessage"]
|
115
|
+
else
|
116
|
+
@password = password
|
117
|
+
@active = active.nil? || active
|
118
|
+
@extra = extra
|
119
|
+
self
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def destroy # TESTED
|
126
|
+
result = self.class.delete("/_api/user/#{@user}", @@request)
|
127
|
+
return_result result: result, caseTrue: true
|
128
|
+
end
|
129
|
+
|
130
|
+
def return_result(result:, caseTrue: false, key: nil)
|
131
|
+
if @@async == "store"
|
132
|
+
result.headers["x-arango-async-id"]
|
133
|
+
else
|
134
|
+
result = result.parsed_response
|
135
|
+
if @@verbose || !result.is_a?(Hash)
|
136
|
+
result
|
137
|
+
else
|
138
|
+
if result["error"]
|
139
|
+
result["errorMessage"]
|
140
|
+
else
|
141
|
+
if caseTrue
|
142
|
+
true
|
143
|
+
elsif key.nil?
|
144
|
+
self
|
145
|
+
else
|
146
|
+
result[key]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/lib/ArangoRB_Ver.rb
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
# ==== DOCUMENT ====
|
4
4
|
|
5
|
-
class
|
6
|
-
def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {})
|
5
|
+
class ArangoVertex < ArangoDocument
|
6
|
+
def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}) # TESTED
|
7
7
|
if collection.is_a?(String)
|
8
8
|
@collection = collection
|
9
|
-
elsif collection.is_a?(
|
9
|
+
elsif collection.is_a?(ArangoCollection)
|
10
10
|
@collection = collection.collection
|
11
11
|
else
|
12
|
-
raise "collection should be a String or an
|
12
|
+
raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
|
13
13
|
end
|
14
14
|
|
15
15
|
if graph.is_a?(String)
|
16
16
|
@graph = graph
|
17
|
-
elsif graph.is_a?(
|
17
|
+
elsif graph.is_a?(ArangoGraph)
|
18
18
|
@graph = graph.graph
|
19
19
|
else
|
20
|
-
raise "graph should be a String or an
|
20
|
+
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
21
21
|
end
|
22
22
|
|
23
23
|
if database.is_a?(String)
|
@@ -47,91 +47,108 @@ class ArangoV < ArangoDoc
|
|
47
47
|
|
48
48
|
# === GET ===
|
49
49
|
|
50
|
-
def retrieve
|
51
|
-
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}")
|
52
|
-
if @@
|
53
|
-
|
54
|
-
result
|
50
|
+
def retrieve # TESTED
|
51
|
+
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", @@request)
|
52
|
+
if @@async == "store"
|
53
|
+
result.headers["x-arango-async-id"]
|
55
54
|
else
|
56
|
-
|
57
|
-
|
55
|
+
result = result.parsed_response
|
56
|
+
if @@verbose
|
57
|
+
@body = result["vertex"] unless result["error"]
|
58
|
+
result
|
58
59
|
else
|
59
|
-
|
60
|
-
|
60
|
+
if result["error"]
|
61
|
+
result["errorMessage"]
|
62
|
+
else
|
63
|
+
@body = result["vertex"]
|
64
|
+
self
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
70
|
# === POST ====
|
66
71
|
|
67
|
-
def create(body: @body, waitForSync: nil)
|
72
|
+
def create(body: @body, waitForSync: nil) # TESTED
|
68
73
|
query = {"waitForSync" => waitForSync}.delete_if{|k,v| v.nil?}
|
69
74
|
body["_key"] = @key if body["_key"].nil? && !@key.nil?
|
70
|
-
|
71
|
-
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@collection}",
|
72
|
-
return_result
|
75
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
76
|
+
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@collection}", request)
|
77
|
+
return_result result: result, body: body
|
73
78
|
end
|
74
79
|
alias create_vertex create
|
75
80
|
|
76
81
|
# === MODIFY ===
|
77
82
|
|
78
|
-
def replace(body: {}, waitForSync: nil)
|
83
|
+
def replace(body: {}, waitForSync: nil) # TESTED
|
79
84
|
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
80
|
-
|
81
|
-
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}",
|
82
|
-
return_result
|
85
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
86
|
+
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
87
|
+
return_result result: result, body: body
|
83
88
|
end
|
84
89
|
|
85
|
-
def update(body: {}, waitForSync: nil, keepNull: nil)
|
90
|
+
def update(body: {}, waitForSync: nil, keepNull: nil) # TESTED
|
86
91
|
query = {"waitForSync" => waitForSync, "keepNull" => keepNull}.delete_if{|k,v| v.nil?}
|
87
|
-
|
88
|
-
result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}",
|
89
|
-
if @@
|
90
|
-
|
91
|
-
@key = result["_key"]
|
92
|
-
@id = "#{@collection}/#{@key}"
|
93
|
-
@body = body
|
94
|
-
end
|
95
|
-
result
|
92
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
93
|
+
result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
94
|
+
if @@async == "store"
|
95
|
+
result.headers["x-arango-async-id"]
|
96
96
|
else
|
97
|
-
|
98
|
-
|
97
|
+
result = result.parsed_response
|
98
|
+
if @@verbose
|
99
|
+
unless result["error"]
|
100
|
+
@key = result["_key"]
|
101
|
+
@id = "#{@collection}/#{@key}"
|
102
|
+
@body = result["vertex"].body
|
103
|
+
end
|
104
|
+
result
|
99
105
|
else
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
106
|
+
if result["error"]
|
107
|
+
result["errorMessage"]
|
108
|
+
else
|
109
|
+
@key = result["vertex"]["_key"]
|
110
|
+
@id = "#{@collection}/#{@key}"
|
111
|
+
@body = @body.merge(body)
|
112
|
+
@body = @body.merge(result["vertex"])
|
113
|
+
self
|
114
|
+
end
|
104
115
|
end
|
105
116
|
end
|
106
117
|
end
|
107
118
|
|
108
119
|
# === DELETE ===
|
109
120
|
|
110
|
-
def destroy(
|
121
|
+
def destroy(waitForSync: nil) # TESTED
|
111
122
|
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
112
|
-
|
113
|
-
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}")
|
114
|
-
|
123
|
+
request = @@request.merge({ :query => query })
|
124
|
+
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
125
|
+
return_result result: result, caseTrue: true
|
115
126
|
end
|
116
127
|
|
117
128
|
# === UTILITY ===
|
118
129
|
|
119
|
-
def return_result(result,
|
120
|
-
if @@
|
121
|
-
|
122
|
-
@key = result["vertex"]["_key"]
|
123
|
-
@id = "#{@collection}/#{@key}"
|
124
|
-
@body = body
|
125
|
-
end
|
126
|
-
result
|
130
|
+
def return_result(result:, body: {}, caseTrue: false)
|
131
|
+
if @@async == "store"
|
132
|
+
result.headers["x-arango-async-id"]
|
127
133
|
else
|
128
|
-
|
129
|
-
|
134
|
+
result = result.parsed_response
|
135
|
+
if @@verbose
|
136
|
+
unless result["error"]
|
137
|
+
@key = result["vertex"]["_key"]
|
138
|
+
@id = "#{@collection}/#{@key}"
|
139
|
+
@body = result["vertex"].merge(body)
|
140
|
+
end
|
141
|
+
result
|
130
142
|
else
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
143
|
+
if result["error"]
|
144
|
+
result["errorMessage"]
|
145
|
+
else
|
146
|
+
return true if caseTrue
|
147
|
+
@key = result["vertex"]["_key"]
|
148
|
+
@id = "#{@collection}/#{@key}"
|
149
|
+
@body = result["vertex"].merge(body)
|
150
|
+
self
|
151
|
+
end
|
135
152
|
end
|
136
153
|
end
|
137
154
|
end
|
data/lib/arangorb.rb
CHANGED
@@ -8,3 +8,7 @@ require_relative "ArangoRB_Ver"
|
|
8
8
|
require_relative "ArangoRB_Edg"
|
9
9
|
require_relative "ArangoRB_Tra"
|
10
10
|
require_relative "ArangoRB_AQL"
|
11
|
+
require_relative "ArangoRB_User"
|
12
|
+
require_relative "ArangoRB_Index"
|
13
|
+
require_relative "ArangoRB_Task"
|
14
|
+
require_relative "ArangoRB_Tran"
|
data/spec/arangoRB_helper.rb
CHANGED
@@ -1,9 +1,2 @@
|
|
1
|
-
require "lib/
|
2
|
-
require "lib/
|
3
|
-
require "lib/arangoC_helper"
|
4
|
-
require "lib/arangoDoc_helper"
|
5
|
-
require "lib/arangoG_helper"
|
6
|
-
require "lib/arangoV_helper"
|
7
|
-
require "lib/arangoE_helper"
|
8
|
-
require "lib/arangoT_helper"
|
9
|
-
require "lib/arangoAQL_helper"
|
1
|
+
require "lib/arangoRB_0.1.0_helper"
|
2
|
+
require "lib/arangoRB_1.0.0_helper"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require_relative File.expand_path('../../lib/arangorb', __FILE__)
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.color = true
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ArangoServer do
|
9
|
+
context "#restart" do
|
10
|
+
it "restart" do
|
11
|
+
print ArangoServer.restart
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,25 +1,6 @@
|
|
1
|
-
require_relative '
|
2
|
-
|
3
|
-
describe ArangoT do
|
4
|
-
before :all do
|
5
|
-
ArangoS.default_server user: "root", password: "tretretre", server: "localhost", port: "8529"
|
6
|
-
ArangoS.database = "MyDatabase"
|
7
|
-
ArangoS.collection = "MyCollection"
|
8
|
-
ArangoS.graph = "MyGraph"
|
9
|
-
ArangoDB.new.create
|
10
|
-
@myGraph = ArangoG.new.create
|
11
|
-
@myCollection = ArangoC.new.create
|
12
|
-
@myEdgeCollection = ArangoC.new(collection: "MyEdgeCollection").create_edge_collection
|
13
|
-
@myGraph.addEdgeCollection collection: "MyEdgeCollection", from: "MyCollection", to: "MyCollection"
|
14
|
-
@myAQL = ArangoAQL.new query: "FOR u IN MyCollection RETURN u.num"
|
15
|
-
@myDoc = @myCollection.create_document document: [{"num" => 1, "_key" => "FirstKey"}, {"num" => 1}, {"num" => 1}, {"num" => 1}, {"num" => 1}, {"num" => 1}, {"num" => 1}, {"num" => 2}, {"num" => 2}, {"num" => 2}, {"num" => 3}, {"num" => 2}, {"num" => 5}, {"num" => 2}]
|
16
|
-
@myEdgeCollection.create_edge from: [@myDoc[0].id, @myDoc[1].id, @myDoc[2].id, @myDoc[3].id, @myDoc[7].id], to: [@myDoc[4].id, @myDoc[5].id, @myDoc[6].id, @myDoc[8].id]
|
17
|
-
end
|
18
|
-
|
19
|
-
after :all do
|
20
|
-
ArangoDB.new.destroy
|
21
|
-
end
|
1
|
+
require_relative './../../spec_helper'
|
22
2
|
|
3
|
+
describe ArangoAQL do
|
23
4
|
context "#new" do
|
24
5
|
it "create a new AQL instance" do
|
25
6
|
myAQL = ArangoAQL.new query: "FOR u IN MyCollection RETURN u.num"
|