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_Tran.rb
CHANGED
@@ -1,53 +1,68 @@
|
|
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
|
-
@result = nil
|
20
|
-
@idCache = "AT_#{@database}_#{Random.rand(0..10^12)}"
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_reader :action, :params, :lockTimeout, :waitForSync, :idCache
|
24
|
-
|
25
|
-
### RETRIEVE ###
|
26
|
-
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
+
@result = nil
|
20
|
+
@idCache = "AT_#{@database}_#{Random.rand(0..10^12)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :action, :params, :lockTimeout, :waitForSync, :idCache
|
24
|
+
|
25
|
+
### RETRIEVE ###
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{
|
29
|
+
"database" => @database,
|
30
|
+
"action" => @action,
|
31
|
+
"collections" => @collections,
|
32
|
+
"result" => @result,
|
33
|
+
"params" => @params,
|
34
|
+
"lockTimeout" => @lockTimeout,
|
35
|
+
"waitForSync" => @waitForSync,
|
36
|
+
"idCache" => @idCache
|
37
|
+
}.delete_if{|k,v| v.nil?}
|
38
|
+
end
|
39
|
+
alias to_h to_hash
|
40
|
+
|
41
|
+
def collections
|
42
|
+
result = {}
|
43
|
+
result["write"] = @collections["write"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["write"].nil?
|
44
|
+
result["read"] = @collections["read"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["read"].nil?
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def database
|
49
|
+
ArangoDatabase.new(database: @database)
|
50
|
+
end
|
51
|
+
|
52
|
+
def execute # TESTED
|
53
|
+
body = {
|
54
|
+
"action" => @action,
|
55
|
+
"collections" => @collections,
|
56
|
+
"params" => @params,
|
57
|
+
"lockTimeout" => @lockTimeout,
|
58
|
+
"waitForSync" => @waitForSync
|
59
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
60
|
+
request = @@request.merge({ :body => body })
|
61
|
+
result = self.class.post("/_db/#{@database}/_api/transaction", request)
|
62
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
63
|
+
return true if @@async
|
64
|
+
result = result.parsed_response
|
65
|
+
@result = result["result"] unless result["error"]
|
66
|
+
@@verbose ? result : result["error"] ? {"message": result["errorMessage"], "stacktrace": result["stacktrace"]} : result["result"]
|
67
|
+
end
|
68
|
+
end
|
data/lib/ArangoRB_User.rb
CHANGED
@@ -1,136 +1,149 @@
|
|
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
|
-
@idCache = "USER_#{@user}"
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :user, :active, :extra, :idCache
|
13
|
-
alias name user
|
14
|
-
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
result
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
+
@idCache = "USER_#{@user}"
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :user, :active, :extra, :idCache
|
13
|
+
alias name user
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
"user" => @user,
|
18
|
+
"active" => @active,
|
19
|
+
"extra" => @extra,
|
20
|
+
"idCache" => @idCache
|
21
|
+
}.delete_if{|k,v| v.nil?}
|
22
|
+
end
|
23
|
+
alias to_h to_hash
|
24
|
+
|
25
|
+
def [](database)
|
26
|
+
if self.databases[database] == "rw"
|
27
|
+
ArangoDatabase.new database: database
|
28
|
+
else
|
29
|
+
"This User does not have access to Database #{database}."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias database []
|
33
|
+
|
34
|
+
def create # TESTED
|
35
|
+
body = {
|
36
|
+
"user" => @user,
|
37
|
+
"passwd" => @password,
|
38
|
+
"active" => @active,
|
39
|
+
"extra" => @extra
|
40
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
41
|
+
request = @@request.merge({ :body => body })
|
42
|
+
result = self.class.post("/_api/user", request)
|
43
|
+
return_result result: result
|
44
|
+
end
|
45
|
+
|
46
|
+
def retrieve # TESTED
|
47
|
+
result = self.class.get("/_api/user/#{@user}", @@request)
|
48
|
+
return_result result: result
|
49
|
+
end
|
50
|
+
|
51
|
+
def grant(database: @@database) # TESTED
|
52
|
+
database = database.database if database.is_a?(ArangoDatabase)
|
53
|
+
body = { "grant" => "rw" }.to_json
|
54
|
+
request = @@request.merge({ :body => body })
|
55
|
+
result = self.class.put("/_api/user/#{@user}/database/#{database}", request)
|
56
|
+
return_result result: result, caseTrue: true
|
57
|
+
end
|
58
|
+
|
59
|
+
def revoke(database: @@database) # TESTED
|
60
|
+
database = database.database if database.is_a?(ArangoDatabase)
|
61
|
+
body = { "grant" => "none" }.to_json
|
62
|
+
request = @@request.merge({ :body => body })
|
63
|
+
result = self.class.put("/_api/user/#{@user}/database/#{database}", request)
|
64
|
+
return_result result: result, caseTrue: true
|
65
|
+
end
|
66
|
+
|
67
|
+
def databases # TESTED
|
68
|
+
result = self.class.get("/_api/user/#{@user}/database/", @@request)
|
69
|
+
return_result result: result, key: "result"
|
70
|
+
end
|
71
|
+
|
72
|
+
def replace(password:, active: nil, extra: nil) # TESTED
|
73
|
+
body = {
|
74
|
+
"passwd" => password,
|
75
|
+
"active" => active,
|
76
|
+
"extra" => extra
|
77
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
78
|
+
request = @@request.merge({ :body => body })
|
79
|
+
result = self.class.put("/_api/user/#{@user}", request)
|
80
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
81
|
+
return true if @@async
|
82
|
+
result = result.parsed_response
|
83
|
+
if @@verbose
|
84
|
+
unless result["error"]
|
85
|
+
@password = password
|
86
|
+
@active = active.nil? || active
|
87
|
+
@extra = extra
|
88
|
+
end
|
89
|
+
result
|
90
|
+
else
|
91
|
+
return result["errorMessage"] if result["error"]
|
92
|
+
@password = password
|
93
|
+
@active = active.nil? || active
|
94
|
+
@extra = extra
|
95
|
+
self
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def update(password: , active: nil, extra: nil) # TESTED
|
100
|
+
body = {
|
101
|
+
"passwd" => password,
|
102
|
+
"active" => active,
|
103
|
+
"extra" => extra
|
104
|
+
}.delete_if{|k,v| v.nil?}.to_json
|
105
|
+
request = @@request.merge({ :body => body })
|
106
|
+
result = self.class.patch("/_api/user/#{@user}", request)
|
107
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
108
|
+
return true if @@async
|
109
|
+
result = result.parsed_response
|
110
|
+
if @@verbose
|
111
|
+
unless result["error"]
|
112
|
+
@password = password
|
113
|
+
@active = active.nil? || active
|
114
|
+
@extra = extra
|
115
|
+
end
|
116
|
+
result
|
117
|
+
else
|
118
|
+
return result["errorMessage"] if result["error"]
|
119
|
+
@password = password
|
120
|
+
@active = active.nil? || active
|
121
|
+
@extra = extra
|
122
|
+
self
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def destroy # TESTED
|
127
|
+
result = self.class.delete("/_api/user/#{@user}", @@request)
|
128
|
+
return_result result: result, caseTrue: true
|
129
|
+
end
|
130
|
+
|
131
|
+
def return_result(result:, caseTrue: false, key: nil)
|
132
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
133
|
+
return true if @@async
|
134
|
+
result = result.parsed_response
|
135
|
+
if @@verbose || !result.is_a?(Hash)
|
136
|
+
unless result["error"]
|
137
|
+
@active = result["active"]
|
138
|
+
@extra = result["extra"]
|
139
|
+
end
|
140
|
+
result
|
141
|
+
else
|
142
|
+
return result["errorMessage"] if result["error"]
|
143
|
+
@active = result["active"]
|
144
|
+
@extra = result["extra"]
|
145
|
+
return true if caseTrue
|
146
|
+
key.nil? ? self : result[key]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/lib/ArangoRB_Ver.rb
CHANGED
@@ -1,147 +1,162 @@
|
|
1
|
-
# === GRAPH VERTEX ===
|
2
|
-
|
3
|
-
# ==== DOCUMENT ====
|
4
|
-
|
5
|
-
class ArangoVertex < ArangoDocument
|
6
|
-
def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}) # TESTED
|
7
|
-
if collection.is_a?(String)
|
8
|
-
@collection = collection
|
9
|
-
elsif collection.is_a?(ArangoCollection)
|
10
|
-
@collection = collection.collection
|
11
|
-
else
|
12
|
-
raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
|
13
|
-
end
|
14
|
-
|
15
|
-
if graph.is_a?(String)
|
16
|
-
@graph = graph
|
17
|
-
elsif graph.is_a?(ArangoGraph)
|
18
|
-
@graph = graph.graph
|
19
|
-
else
|
20
|
-
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
21
|
-
end
|
22
|
-
|
23
|
-
if database.is_a?(String)
|
24
|
-
@database = database
|
25
|
-
else
|
26
|
-
raise "database should be a String, not a #{database.class}"
|
27
|
-
end
|
28
|
-
|
29
|
-
if key.is_a?(String) || key.nil?
|
30
|
-
@key = key
|
31
|
-
unless key.nil?
|
32
|
-
body["_key"] = @key
|
33
|
-
@id = "#{@collection}/#{@key}"
|
34
|
-
end
|
35
|
-
elsif key.is_a?(ArangoDocument)
|
36
|
-
@key = key.key
|
37
|
-
@id = key.id
|
38
|
-
else
|
39
|
-
raise "key should be a String, not a #{key.class}"
|
40
|
-
end
|
41
|
-
|
42
|
-
if body.is_a?(Hash)
|
43
|
-
@body = body
|
44
|
-
else
|
45
|
-
raise "body should be a Hash, not a #{body.class}"
|
46
|
-
end
|
47
|
-
@idCache = "VER_#{@id}"
|
48
|
-
end
|
49
|
-
|
50
|
-
attr_reader :key, :id, :body, :idCache
|
51
|
-
|
52
|
-
# === RETRIEVE ===
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
1
|
+
# === GRAPH VERTEX ===
|
2
|
+
|
3
|
+
# ==== DOCUMENT ====
|
4
|
+
|
5
|
+
class ArangoVertex < ArangoDocument
|
6
|
+
def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}) # TESTED
|
7
|
+
if collection.is_a?(String)
|
8
|
+
@collection = collection
|
9
|
+
elsif collection.is_a?(ArangoCollection)
|
10
|
+
@collection = collection.collection
|
11
|
+
else
|
12
|
+
raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
|
13
|
+
end
|
14
|
+
|
15
|
+
if graph.is_a?(String)
|
16
|
+
@graph = graph
|
17
|
+
elsif graph.is_a?(ArangoGraph)
|
18
|
+
@graph = graph.graph
|
19
|
+
else
|
20
|
+
raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
|
21
|
+
end
|
22
|
+
|
23
|
+
if database.is_a?(String)
|
24
|
+
@database = database
|
25
|
+
else
|
26
|
+
raise "database should be a String, not a #{database.class}"
|
27
|
+
end
|
28
|
+
|
29
|
+
if key.is_a?(String) || key.nil?
|
30
|
+
@key = key
|
31
|
+
unless key.nil?
|
32
|
+
body["_key"] = @key
|
33
|
+
@id = "#{@collection}/#{@key}"
|
34
|
+
end
|
35
|
+
elsif key.is_a?(ArangoDocument)
|
36
|
+
@key = key.key
|
37
|
+
@id = key.id
|
38
|
+
else
|
39
|
+
raise "key should be a String, not a #{key.class}"
|
40
|
+
end
|
41
|
+
|
42
|
+
if body.is_a?(Hash)
|
43
|
+
@body = body
|
44
|
+
else
|
45
|
+
raise "body should be a Hash, not a #{body.class}"
|
46
|
+
end
|
47
|
+
@idCache = "VER_#{@id}"
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :key, :id, :body, :idCache
|
51
|
+
|
52
|
+
# === RETRIEVE ===
|
53
|
+
|
54
|
+
def to_hash
|
55
|
+
{
|
56
|
+
"key" => @key,
|
57
|
+
"id" => @id,
|
58
|
+
"collection" => @collection,
|
59
|
+
"database" => @database,
|
60
|
+
"body" => @body,
|
61
|
+
"idCache" => @idCache
|
62
|
+
}.delete_if{|k,v| v.nil?}
|
63
|
+
end
|
64
|
+
alias to_h to_hash
|
65
|
+
|
66
|
+
def graph
|
67
|
+
ArangoGraph.new(graph: @graph, database: @database)
|
68
|
+
end
|
69
|
+
|
70
|
+
# === GET ===
|
71
|
+
|
72
|
+
def retrieve # TESTED
|
73
|
+
result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", @@request)
|
74
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
75
|
+
return true if @@async
|
76
|
+
result = result.parsed_response
|
77
|
+
if @@verbose
|
78
|
+
@body = result["vertex"] unless result["error"]
|
79
|
+
result
|
80
|
+
else
|
81
|
+
return result["errorMessage"] if result["error"]
|
82
|
+
@body = result["vertex"]
|
83
|
+
self
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# === POST ====
|
88
|
+
|
89
|
+
def create(body: @body, waitForSync: nil) # TESTED
|
90
|
+
query = {"waitForSync" => waitForSync}.delete_if{|k,v| v.nil?}
|
91
|
+
body["_key"] = @key if body["_key"].nil? && !@key.nil?
|
92
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
93
|
+
result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@collection}", request)
|
94
|
+
return_result result: result, body: body
|
95
|
+
end
|
96
|
+
alias create_vertex create
|
97
|
+
|
98
|
+
# === MODIFY ===
|
99
|
+
|
100
|
+
def replace(body: {}, waitForSync: nil) # TESTED
|
101
|
+
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
102
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
103
|
+
result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
104
|
+
return_result result: result, body: body
|
105
|
+
end
|
106
|
+
|
107
|
+
def update(body: {}, waitForSync: nil, keepNull: nil) # TESTED
|
108
|
+
query = {"waitForSync" => waitForSync, "keepNull" => keepNull}.delete_if{|k,v| v.nil?}
|
109
|
+
request = @@request.merge({ :body => body.to_json, :query => query })
|
110
|
+
result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
111
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
112
|
+
return true if @@async
|
113
|
+
result = result.parsed_response
|
114
|
+
if @@verbose
|
115
|
+
unless result["error"]
|
116
|
+
@key = result["_key"]
|
117
|
+
@id = "#{@collection}/#{@key}"
|
118
|
+
@body = result["vertex"].body
|
119
|
+
end
|
120
|
+
result
|
121
|
+
else
|
122
|
+
return result["errorMessage"] if result["error"]
|
123
|
+
@key = result["vertex"]["_key"]
|
124
|
+
@id = "#{@collection}/#{@key}"
|
125
|
+
@body = @body.merge(body)
|
126
|
+
@body = @body.merge(result["vertex"])
|
127
|
+
self
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# === DELETE ===
|
132
|
+
|
133
|
+
def destroy(waitForSync: nil) # TESTED
|
134
|
+
query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
|
135
|
+
request = @@request.merge({ :query => query })
|
136
|
+
result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{@id}", request)
|
137
|
+
return_result result: result, caseTrue: true
|
138
|
+
end
|
139
|
+
|
140
|
+
# === UTILITY ===
|
141
|
+
|
142
|
+
def return_result(result:, body: {}, caseTrue: false)
|
143
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
144
|
+
return true if @@async
|
145
|
+
result = result.parsed_response
|
146
|
+
if @@verbose
|
147
|
+
unless result["error"]
|
148
|
+
@key = result["vertex"]["_key"]
|
149
|
+
@id = "#{@collection}/#{@key}"
|
150
|
+
@body = result["vertex"].merge(body)
|
151
|
+
end
|
152
|
+
result
|
153
|
+
else
|
154
|
+
return result["errorMessage"] if result["error"]
|
155
|
+
return true if caseTrue
|
156
|
+
@key = result["vertex"]["_key"]
|
157
|
+
@id = "#{@collection}/#{@key}"
|
158
|
+
@body = result["vertex"].merge(body)
|
159
|
+
self
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|