arangorb 1.0.0 → 1.1.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 +1 -1
- data/README.md +26 -1
- data/lib/ArangoRB_AQL.rb +30 -60
- data/lib/ArangoRB_Col.rb +89 -258
- data/lib/ArangoRB_DB.rb +18 -90
- data/lib/ArangoRB_Doc.rb +46 -45
- data/lib/ArangoRB_Edg.rb +48 -57
- data/lib/ArangoRB_Gra.rb +66 -105
- data/lib/ArangoRB_Index.rb +41 -72
- data/lib/ArangoRB_Ser.rb +21 -65
- data/lib/ArangoRB_Task.rb +33 -57
- data/lib/ArangoRB_Tra.rb +31 -35
- data/lib/ArangoRB_Tran.rb +17 -15
- data/lib/ArangoRB_User.rb +54 -71
- data/lib/ArangoRB_Ver.rb +48 -57
- data/spec/arangoRB_helper.rb +1 -0
- data/spec/lib/0.1.0/arangoC_helper.rb +2 -2
- data/spec/lib/0.1.0/arangoDoc_helper.rb +1 -1
- data/spec/lib/0.1.0/arangoE_helper.rb +1 -1
- data/spec/lib/0.1.0/arangoS_helper.rb +3 -3
- data/spec/lib/0.1.0/arangoT_helper.rb +4 -4
- data/spec/lib/0.1.0/arangoV_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoDB_helper.rb +0 -33
- data/spec/lib/1.0.0/arangoS_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoTa_helper.rb +1 -1
- data/spec/lib/1.0.0/arangoTr_helper.rb +1 -1
- data/spec/lib/1.1.0/arangoRB_helper.rb +144 -0
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +18 -0
- data/spec/lib/arangoRB_1.1.0_helper.rb +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -3
data/lib/ArangoRB_Tran.rb
CHANGED
@@ -18,7 +18,20 @@ class ArangoTransaction < ArangoServer
|
|
18
18
|
@waitForSync = waitForSync
|
19
19
|
end
|
20
20
|
|
21
|
-
attr_reader :action, :
|
21
|
+
attr_reader :action, :params, :lockTimeout, :waitForSync
|
22
|
+
|
23
|
+
### RETRIEVE ###
|
24
|
+
|
25
|
+
def collections
|
26
|
+
result = {}
|
27
|
+
result["write"] = @collections["write"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["write"].nil?
|
28
|
+
result["read"] = @collections["read"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["read"].nil?
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def database
|
33
|
+
ArangoDatabase.new(database: @database)
|
34
|
+
end
|
22
35
|
|
23
36
|
def execute # TESTED
|
24
37
|
body = {
|
@@ -30,19 +43,8 @@ class ArangoTransaction < ArangoServer
|
|
30
43
|
}.delete_if{|k,v| v.nil?}.to_json
|
31
44
|
request = @@request.merge({ :body => body })
|
32
45
|
result = self.class.post("/_db/#{@database}/_api/transaction", request)
|
33
|
-
if @@async == "store"
|
34
|
-
|
35
|
-
|
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
|
46
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
47
|
+
result = result.parsed_response
|
48
|
+
@@verbose ? result : result["error"] ? {"message": result["errorMessage"], "stacktrace": result["stacktrace"]} : result["result"]
|
47
49
|
end
|
48
50
|
end
|
data/lib/ArangoRB_User.rb
CHANGED
@@ -9,31 +9,31 @@ class ArangoUser < ArangoServer
|
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_reader :user, :active, :extra
|
12
|
+
alias name user
|
12
13
|
|
13
|
-
def
|
14
|
+
def [](database)
|
15
|
+
if self.databases[database] == "rw"
|
16
|
+
ArangoDatabase.new database: database
|
17
|
+
else
|
18
|
+
"This User does not have access to Database #{database}."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
alias database []
|
22
|
+
|
23
|
+
def create # TESTED
|
14
24
|
body = {
|
15
25
|
"user" => @user,
|
16
26
|
"passwd" => @password,
|
17
|
-
"active" => active,
|
18
|
-
"extra" => extra
|
27
|
+
"active" => @active,
|
28
|
+
"extra" => @extra
|
19
29
|
}.delete_if{|k,v| v.nil?}.to_json
|
20
30
|
request = @@request.merge({ :body => body })
|
21
31
|
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
32
|
return_result result: result
|
28
33
|
end
|
29
34
|
|
30
35
|
def retrieve # TESTED
|
31
36
|
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
37
|
return_result result: result
|
38
38
|
end
|
39
39
|
|
@@ -66,27 +66,21 @@ class ArangoUser < ArangoServer
|
|
66
66
|
}.delete_if{|k,v| v.nil?}.to_json
|
67
67
|
request = @@request.merge({ :body => body })
|
68
68
|
result = self.class.put("/_api/user/#{@user}", request)
|
69
|
-
if @@async == "store"
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
69
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
70
|
+
result = result.parsed_response
|
71
|
+
if @@verbose
|
72
|
+
unless result["error"]
|
73
|
+
@password = password
|
74
|
+
@active = active.nil? || active
|
75
|
+
@extra = extra
|
89
76
|
end
|
77
|
+
result
|
78
|
+
else
|
79
|
+
return result["errorMessage"] if result["error"]
|
80
|
+
@password = password
|
81
|
+
@active = active.nil? || active
|
82
|
+
@extra = extra
|
83
|
+
self
|
90
84
|
end
|
91
85
|
end
|
92
86
|
|
@@ -98,27 +92,21 @@ class ArangoUser < ArangoServer
|
|
98
92
|
}.delete_if{|k,v| v.nil?}.to_json
|
99
93
|
request = @@request.merge({ :body => body })
|
100
94
|
result = self.class.patch("/_api/user/#{@user}", request)
|
101
|
-
if @@async == "store"
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
95
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
96
|
+
result = result.parsed_response
|
97
|
+
if @@verbose
|
98
|
+
unless result["error"]
|
99
|
+
@password = password
|
100
|
+
@active = active.nil? || active
|
101
|
+
@extra = extra
|
121
102
|
end
|
103
|
+
result
|
104
|
+
else
|
105
|
+
return result["errorMessage"] if result["error"]
|
106
|
+
@password = password
|
107
|
+
@active = active.nil? || active
|
108
|
+
@extra = extra
|
109
|
+
self
|
122
110
|
end
|
123
111
|
end
|
124
112
|
|
@@ -128,25 +116,20 @@ class ArangoUser < ArangoServer
|
|
128
116
|
end
|
129
117
|
|
130
118
|
def return_result(result:, caseTrue: false, key: nil)
|
131
|
-
if @@async == "store"
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
119
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
120
|
+
result = result.parsed_response
|
121
|
+
if @@verbose || !result.is_a?(Hash)
|
122
|
+
unless result["error"]
|
123
|
+
@active = result["active"]
|
124
|
+
@extra = result["extra"]
|
149
125
|
end
|
126
|
+
result
|
127
|
+
else
|
128
|
+
return result["errorMessage"] if result["error"]
|
129
|
+
@active = result["active"]
|
130
|
+
@extra = result["extra"]
|
131
|
+
return true if caseTrue
|
132
|
+
key.nil? ? self : result[key]
|
150
133
|
end
|
151
134
|
end
|
152
135
|
end
|
data/lib/ArangoRB_Ver.rb
CHANGED
@@ -32,6 +32,9 @@ class ArangoVertex < ArangoDocument
|
|
32
32
|
body["_key"] = @key
|
33
33
|
@id = "#{@collection}/#{@key}"
|
34
34
|
end
|
35
|
+
elsif key.is_a?(ArangoDocument)
|
36
|
+
@key = key.key
|
37
|
+
@id = key.id
|
35
38
|
else
|
36
39
|
raise "key should be a String, not a #{key.class}"
|
37
40
|
end
|
@@ -43,27 +46,27 @@ class ArangoVertex < ArangoDocument
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
46
|
-
attr_reader :key, :id, :body
|
49
|
+
attr_reader :key, :id, :body
|
50
|
+
|
51
|
+
# === RETRIEVE ===
|
52
|
+
|
53
|
+
def graph
|
54
|
+
ArangoGraph.new(graph: @graph, database: @database)
|
55
|
+
end
|
47
56
|
|
48
57
|
# === GET ===
|
49
58
|
|
50
59
|
def retrieve # TESTED
|
51
60
|
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", @@request)
|
52
|
-
if @@async == "store"
|
53
|
-
|
61
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
62
|
+
result = result.parsed_response
|
63
|
+
if @@verbose
|
64
|
+
@body = result["vertex"] unless result["error"]
|
65
|
+
result
|
54
66
|
else
|
55
|
-
result
|
56
|
-
|
57
|
-
|
58
|
-
result
|
59
|
-
else
|
60
|
-
if result["error"]
|
61
|
-
result["errorMessage"]
|
62
|
-
else
|
63
|
-
@body = result["vertex"]
|
64
|
-
self
|
65
|
-
end
|
66
|
-
end
|
67
|
+
return result["errorMessage"] if result["error"]
|
68
|
+
@body = result["vertex"]
|
69
|
+
self
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
@@ -91,28 +94,22 @@ class ArangoVertex < ArangoDocument
|
|
91
94
|
query = {"waitForSync" => waitForSync, "keepNull" => keepNull}.delete_if{|k,v| v.nil?}
|
92
95
|
request = @@request.merge({ :body => body.to_json, :query => query })
|
93
96
|
result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
94
|
-
if @@async == "store"
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@id = "#{@collection}/#{@key}"
|
102
|
-
@body = result["vertex"].body
|
103
|
-
end
|
104
|
-
result
|
105
|
-
else
|
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
|
97
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
98
|
+
result = result.parsed_response
|
99
|
+
if @@verbose
|
100
|
+
unless result["error"]
|
101
|
+
@key = result["_key"]
|
102
|
+
@id = "#{@collection}/#{@key}"
|
103
|
+
@body = result["vertex"].body
|
115
104
|
end
|
105
|
+
result
|
106
|
+
else
|
107
|
+
return result["errorMessage"] if result["error"]
|
108
|
+
@key = result["vertex"]["_key"]
|
109
|
+
@id = "#{@collection}/#{@key}"
|
110
|
+
@body = @body.merge(body)
|
111
|
+
@body = @body.merge(result["vertex"])
|
112
|
+
self
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
@@ -128,28 +125,22 @@ class ArangoVertex < ArangoDocument
|
|
128
125
|
# === UTILITY ===
|
129
126
|
|
130
127
|
def return_result(result:, body: {}, caseTrue: false)
|
131
|
-
if @@async == "store"
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
@id = "#{@collection}/#{@key}"
|
139
|
-
@body = result["vertex"].merge(body)
|
140
|
-
end
|
141
|
-
result
|
142
|
-
else
|
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
|
128
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
129
|
+
result = result.parsed_response
|
130
|
+
if @@verbose
|
131
|
+
unless result["error"]
|
132
|
+
@key = result["vertex"]["_key"]
|
133
|
+
@id = "#{@collection}/#{@key}"
|
134
|
+
@body = result["vertex"].merge(body)
|
152
135
|
end
|
136
|
+
result
|
137
|
+
else
|
138
|
+
return result["errorMessage"] if result["error"]
|
139
|
+
return true if caseTrue
|
140
|
+
@key = result["vertex"]["_key"]
|
141
|
+
@id = "#{@collection}/#{@key}"
|
142
|
+
@body = result["vertex"].merge(body)
|
143
|
+
self
|
153
144
|
end
|
154
145
|
end
|
155
146
|
end
|
data/spec/arangoRB_helper.rb
CHANGED
@@ -91,7 +91,7 @@ describe ArangoCollection do
|
|
91
91
|
|
92
92
|
it "search Document by match" do
|
93
93
|
info = @myCollection.documentMatch match: {"num" => 1}
|
94
|
-
expect(info.collection).to eq "MyCollection"
|
94
|
+
expect(info.collection.name).to eq "MyCollection"
|
95
95
|
end
|
96
96
|
|
97
97
|
it "search Document by key match" do
|
@@ -126,7 +126,7 @@ describe ArangoCollection do
|
|
126
126
|
|
127
127
|
it "search random Document" do
|
128
128
|
info = @myCollection.random
|
129
|
-
expect(info.collection).to eq "MyCollection"
|
129
|
+
expect(info.collection.name).to eq "MyCollection"
|
130
130
|
end
|
131
131
|
|
132
132
|
|
@@ -4,7 +4,7 @@ describe ArangoDocument do
|
|
4
4
|
context "#new" do
|
5
5
|
it "create a new Document instance without global" do
|
6
6
|
myDocument = ArangoDocument.new collection: "MyCollection", database: "MyDatabase"
|
7
|
-
expect(myDocument.collection).to eq "MyCollection"
|
7
|
+
expect(myDocument.collection.name).to eq "MyCollection"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "create a new instance with global" do
|
@@ -4,21 +4,21 @@ describe ArangoServer do
|
|
4
4
|
context "#database" do
|
5
5
|
it "setup a global database" do
|
6
6
|
ArangoServer.database = "MyDatabase"
|
7
|
-
expect(ArangoServer.database).to eq "MyDatabase"
|
7
|
+
expect(ArangoServer.database.name).to eq "MyDatabase"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
context "#graph" do
|
12
12
|
it "setup a global graph" do
|
13
13
|
ArangoServer.graph = "MyGraph"
|
14
|
-
expect(ArangoServer.graph).to eq "MyGraph"
|
14
|
+
expect(ArangoServer.graph.name).to eq "MyGraph"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "#collection" do
|
19
19
|
it "setup a global collection" do
|
20
20
|
ArangoServer.collection = "MyCollection"
|
21
|
-
expect(ArangoServer.collection).to eq "MyCollection"
|
21
|
+
expect(ArangoServer.collection.name).to eq "MyCollection"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -4,22 +4,22 @@ describe ArangoTraversal do
|
|
4
4
|
context "#new" do
|
5
5
|
it "create a new Traversal instance" do
|
6
6
|
myTraversal = ArangoTraversal.new
|
7
|
-
expect(myTraversal.database).to eq "MyDatabase"
|
7
|
+
expect(myTraversal.database.name).to eq "MyDatabase"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "instantiate start Vertex" do
|
11
11
|
@myTraversal.vertex = @myDoc[0]
|
12
|
-
expect(@myTraversal.vertex).to eq "MyCollection/FirstKey"
|
12
|
+
expect(@myTraversal.vertex.id).to eq "MyCollection/FirstKey"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "instantiate Graph" do
|
16
16
|
@myTraversal.graph = @myGraph
|
17
|
-
expect(@myTraversal.graph).to eq @myGraph.graph
|
17
|
+
expect(@myTraversal.graph.name).to eq @myGraph.graph
|
18
18
|
end
|
19
19
|
|
20
20
|
it "instantiate EdgeCollection" do
|
21
21
|
@myTraversal.collection = @myEdgeCollection
|
22
|
-
expect(@myTraversal.collection).to eq @myEdgeCollection.collection
|
22
|
+
expect(@myTraversal.collection.name).to eq @myEdgeCollection.collection
|
23
23
|
end
|
24
24
|
|
25
25
|
it "instantiate Direction" do
|