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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ArangoRB.gemspec +18 -18
  3. data/Gemfile +8 -7
  4. data/LICENSE +21 -21
  5. data/README.md +906 -867
  6. data/lib/ArangoRB_AQL.rb +181 -160
  7. data/lib/ArangoRB_Cache.rb +174 -174
  8. data/lib/ArangoRB_Col.rb +526 -499
  9. data/lib/ArangoRB_DB.rb +363 -339
  10. data/lib/ArangoRB_Doc.rb +319 -298
  11. data/lib/ArangoRB_Edg.rb +184 -169
  12. data/lib/ArangoRB_Gra.rb +201 -180
  13. data/lib/ArangoRB_Index.rb +135 -115
  14. data/lib/ArangoRB_Replication.rb +261 -0
  15. data/lib/ArangoRB_Ser.rb +446 -441
  16. data/lib/ArangoRB_Task.rb +129 -113
  17. data/lib/ArangoRB_Tra.rb +169 -142
  18. data/lib/ArangoRB_Tran.rb +68 -53
  19. data/lib/ArangoRB_User.rb +149 -136
  20. data/lib/ArangoRB_Ver.rb +162 -147
  21. data/lib/arangorb.rb +16 -15
  22. data/spec/arangoRB_helper.rb +4 -4
  23. data/spec/arangoRestart_helper.rb +14 -14
  24. data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
  25. data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
  26. data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
  27. data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
  28. data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
  29. data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
  30. data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
  31. data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
  32. data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
  33. data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
  34. data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
  35. data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
  36. data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
  37. data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
  38. data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
  39. data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
  40. data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
  41. data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
  42. data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
  43. data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
  44. data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
  45. data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
  46. data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
  47. data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
  48. data/spec/spec_helper.rb +41 -41
  49. metadata +6 -5
@@ -1,160 +1,181 @@
1
- # === AQL ===
2
-
3
- class ArangoAQL < ArangoServer
4
- def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) # TESTED
5
- if query.is_a?(String)
6
- @query = query
7
- elsif query.is_a?(ArangoAQL)
8
- @query = query.query
9
- else
10
- raise "query should be String or ArangoAQL instance, not a #{query.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 "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
19
- end
20
-
21
- @batchSize = batchSize
22
- @ttl = ttl
23
- @cache = cache
24
- @options = options
25
- @bindVars = bindVars
26
-
27
- @count = 0
28
- @hasMore = false
29
- @id = ""
30
- @result = []
31
- @idCache = "AQL_#{@query}"
32
- end
33
-
34
- attr_accessor :query, :batchSize, :ttl, :cache, :options, :bindVars
35
- attr_reader :count, :count, :hasMore, :id, :result, :idCache
36
- alias size batchSize
37
- alias size= batchSize=
38
-
39
- # === RETRIEVE ===
40
-
41
- def database
42
- ArangoDatabase.new(database: @database)
43
- end
44
-
45
- # === EXECUTE QUERY ===
46
-
47
- def execute(count: true) # TESTED
48
- body = {
49
- "query" => @query,
50
- "count" => count,
51
- "batchSize" => @batchSize,
52
- "ttl" => @count,
53
- "cache" => @cache,
54
- "options" => @options,
55
- "bindVars" => @bindVars
56
- }.delete_if{|k,v| v.nil?}
57
- request = @@request.merge({ :body => body.to_json })
58
- result = self.class.post("/_db/#{@database}/_api/cursor", request)
59
- return result.headers["x-arango-async-id"]if @@async == "store"
60
- result = result.parsed_response
61
- return @@verbose ? result : result["errorMessage"] if result["error"]
62
- @count = result["count"]
63
- @hasMore = result["hasMore"]
64
- @id = result["id"]
65
- if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
66
- @result = result["result"]
67
- else
68
- @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
69
- end
70
- return @@verbose ? result : self
71
- end
72
-
73
- def next # TESTED
74
- unless @hasMore
75
- print "No other results"
76
- else
77
- result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
78
- return result.headers["x-arango-async-id"]if @@async == "store"
79
- result = result.parsed_response
80
- return @@verbose ? result : result["errorMessage"] if result["error"]
81
- @count = result["count"]
82
- @hasMore = result["hasMore"]
83
- @id = result["id"]
84
- if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
85
- @result = result["result"]
86
- else
87
- @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
88
- end
89
- return @@verbose ? result : self
90
- end
91
- end
92
-
93
- # === PROPERTY QUERY ===
94
-
95
- def explain # TESTED
96
- body = {
97
- "query" => @query,
98
- "options" => @options,
99
- "bindVars" => @bindVars
100
- }.delete_if{|k,v| v.nil?}
101
- request = @@request.merge({ :body => body.to_json })
102
- result = self.class.post("/_db/#{@database}/_api/explain", request)
103
- return_result result: result
104
- end
105
-
106
- def parse # TESTED
107
- body = { "query" => @query }
108
- request = @@request.merge({ :body => body.to_json })
109
- result = self.class.post("/_db/#{@database}/_api/query", request)
110
- return_result result: result
111
- end
112
-
113
- def properties # TESTED
114
- result = self.class.get("/_db/#{@database}/_api/query/properties", @@request)
115
- return_result result: result
116
- end
117
-
118
- def current # TESTED
119
- result = self.class.get("/_db/#{@database}/_api/query/current", @@request)
120
- return_result result: result
121
- end
122
-
123
- def slow # TESTED
124
- result = self.class.get("/_db/#{@database}/_api/query/slow", @@request)
125
- return_result result: result
126
- end
127
-
128
- # === DELETE ===
129
-
130
- def stopSlow # TESTED
131
- result = self.class.delete("/_db/#{@database}/_api/query/slow", @@request)
132
- return_result result: result, caseTrue: true
133
- end
134
-
135
- def kill(id: @id) # TESTED
136
- result = self.class.delete("/_db/#{@database}/_api/query/#{id}", @@request)
137
- return_result result: result, caseTrue: true
138
- end
139
-
140
- def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) # TESTED
141
- body = {
142
- "slowQueryThreshold" => slowQueryThreshold,
143
- "enabled" => enabled,
144
- "maxSlowQueries" => maxSlowQueries,
145
- "trackSlowQueries" => trackSlowQueries,
146
- "maxQueryStringLength" => maxQueryStringLength
147
- }.delete_if{|k,v| v.nil?}
148
- request = @@request.merge({ :body => body.to_json })
149
- result = self.class.put("/_db/#{@database}/_api/query/properties", request)
150
- return_result result: result
151
- end
152
-
153
- # === UTILITY ===
154
-
155
- def return_result(result:, caseTrue: false)
156
- return result.headers["x-arango-async-id"] if @@async == "store"
157
- result = result.parsed_response
158
- @@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : caseTrue ? true : result
159
- end
160
- end
1
+ # === AQL ===
2
+
3
+ class ArangoAQL < ArangoServer
4
+ def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) # TESTED
5
+ if query.is_a?(String)
6
+ @query = query
7
+ elsif query.is_a?(ArangoAQL)
8
+ @query = query.query
9
+ else
10
+ raise "query should be String or ArangoAQL instance, not a #{query.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 "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
19
+ end
20
+
21
+ @batchSize = batchSize
22
+ @ttl = ttl
23
+ @cache = cache
24
+ @options = options
25
+ @bindVars = bindVars
26
+
27
+ @count = true
28
+ @quantity = nil
29
+ @hasMore = false
30
+ @id = ""
31
+ @result = []
32
+ @idCache = "AQL_#{@query}"
33
+ end
34
+
35
+ attr_accessor :count, :query, :batchSize, :ttl, :cache, :options, :bindVars, :quantity
36
+ attr_reader :hasMore, :id, :result, :idCache
37
+ alias size batchSize
38
+ alias size= batchSize=
39
+
40
+ # === RETRIEVE ===
41
+
42
+ def to_hash
43
+ {
44
+ "query" => @query,
45
+ "database" => @database,
46
+ "result" => @result.map{|x| x.is_a?(ArangoServer) ? x.to_h : x},
47
+ "count" => @count,
48
+ "quantity" => @quantity,
49
+ "ttl" => @ttl,
50
+ "cache" => @cache,
51
+ "batchSize" => @batchSize,
52
+ "bindVars" => @bindVars,
53
+ "options" => @options,
54
+ "idCache" => @idCache,
55
+ }.delete_if{|k,v| v.nil?}
56
+ end
57
+ alias to_h to_hash
58
+
59
+ def database
60
+ ArangoDatabase.new(database: @database)
61
+ end
62
+
63
+ # === EXECUTE QUERY ===
64
+
65
+ def execute # TESTED
66
+ body = {
67
+ "query" => @query,
68
+ "count" => count,
69
+ "batchSize" => @batchSize,
70
+ "ttl" => @ttl,
71
+ "cache" => @cache,
72
+ "options" => @options,
73
+ "bindVars" => @bindVars
74
+ }.delete_if{|k,v| v.nil?}
75
+ request = @@request.merge({ :body => body.to_json })
76
+ result = self.class.post("/_db/#{@database}/_api/cursor", request)
77
+ return result.headers["x-arango-async-id"] if @@async == "store"
78
+ return true if @@async
79
+ result = result.parsed_response
80
+ return @@verbose ? result : result["errorMessage"] if result["error"]
81
+ @quantity = result["count"]
82
+ @hasMore = result["hasMore"]
83
+ @id = result["id"]
84
+ if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
85
+ @result = result["result"]
86
+ else
87
+ @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
88
+ end
89
+ return @@verbose ? result : self
90
+ end
91
+
92
+ def next # TESTED
93
+ unless @hasMore
94
+ print "No other results"
95
+ else
96
+ result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
97
+ return result.headers["x-arango-async-id"] if @@async == "store"
98
+ return true if @@async
99
+ result = result.parsed_response
100
+ return @@verbose ? result : result["errorMessage"] if result["error"]
101
+ @count = result["count"]
102
+ @hasMore = result["hasMore"]
103
+ @id = result["id"]
104
+ if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
105
+ @result = result["result"]
106
+ else
107
+ @result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
108
+ end
109
+ return @@verbose ? result : self
110
+ end
111
+ end
112
+
113
+ # === PROPERTY QUERY ===
114
+
115
+ def explain # TESTED
116
+ body = {
117
+ "query" => @query,
118
+ "options" => @options,
119
+ "bindVars" => @bindVars
120
+ }.delete_if{|k,v| v.nil?}
121
+ request = @@request.merge({ :body => body.to_json })
122
+ result = self.class.post("/_db/#{@database}/_api/explain", request)
123
+ return_result result: result
124
+ end
125
+
126
+ def parse # TESTED
127
+ body = { "query" => @query }
128
+ request = @@request.merge({ :body => body.to_json })
129
+ result = self.class.post("/_db/#{@database}/_api/query", request)
130
+ return_result result: result
131
+ end
132
+
133
+ def properties # TESTED
134
+ result = self.class.get("/_db/#{@database}/_api/query/properties", @@request)
135
+ return_result result: result
136
+ end
137
+
138
+ def current # TESTED
139
+ result = self.class.get("/_db/#{@database}/_api/query/current", @@request)
140
+ return_result result: result
141
+ end
142
+
143
+ def slow # TESTED
144
+ result = self.class.get("/_db/#{@database}/_api/query/slow", @@request)
145
+ return_result result: result
146
+ end
147
+
148
+ # === DELETE ===
149
+
150
+ def stopSlow # TESTED
151
+ result = self.class.delete("/_db/#{@database}/_api/query/slow", @@request)
152
+ return_result result: result, caseTrue: true
153
+ end
154
+
155
+ def kill(id: @id) # TESTED
156
+ result = self.class.delete("/_db/#{@database}/_api/query/#{id}", @@request)
157
+ return_result result: result, caseTrue: true
158
+ end
159
+
160
+ def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) # TESTED
161
+ body = {
162
+ "slowQueryThreshold" => slowQueryThreshold,
163
+ "enabled" => enabled,
164
+ "maxSlowQueries" => maxSlowQueries,
165
+ "trackSlowQueries" => trackSlowQueries,
166
+ "maxQueryStringLength" => maxQueryStringLength
167
+ }.delete_if{|k,v| v.nil?}
168
+ request = @@request.merge({ :body => body.to_json })
169
+ result = self.class.put("/_db/#{@database}/_api/query/properties", request)
170
+ return_result result: result
171
+ end
172
+
173
+ # === UTILITY ===
174
+
175
+ def return_result(result:, caseTrue: false)
176
+ return result.headers["x-arango-async-id"] if @@async == "store"
177
+ return true if @@async
178
+ result = result.parsed_response
179
+ @@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : caseTrue ? true : result
180
+ end
181
+ end
@@ -1,174 +1,174 @@
1
- # ==== CACHE ====
2
-
3
- class ArangoCache
4
- @max = {
5
- "Database" => 1,
6
- "Collection" => 20,
7
- "Document" => 200,
8
- "Graph" => 1,
9
- "Vertex" => 50,
10
- "Edge" => 100,
11
- "Index" => 20,
12
- "AQL" => 100,
13
- "User" => 50,
14
- "Task" => 20,
15
- "Traversal" => 20,
16
- "Transaction" => 20,
17
- "Other" => 100
18
- }
19
- @cache = {
20
- "Database" => {},
21
- "Collection" => {},
22
- "Document" => {},
23
- "Graph" => {},
24
- "Vertex" => {},
25
- "Edge" => {},
26
- "Index" => {},
27
- "AQL" => {},
28
- "User" => {},
29
- "Task" => {},
30
- "Traversal" => {},
31
- "Transaction" => {},
32
- "Other" => {}
33
- }
34
-
35
- class << self
36
- attr_accessor :max
37
-
38
- def max(type:, val:)
39
- return nil if @max[type].nil?
40
- while @cache[type].length > val
41
- @cache[type].shift
42
- end
43
- @max[type] = val
44
- end
45
-
46
- def retrieve
47
- @cache
48
- end
49
-
50
- def cache(id: nil, data:)
51
- val_to_cache = []
52
- data = [data] unless data.is_a? Array
53
-
54
- if id.nil?
55
- data.each do |d|
56
- type = d.class.to_s
57
- type.slice! "Arango"
58
- if @max[type].nil?
59
- type = "Other"
60
- idCache = "OTH_#{d.class.to_s}_#{Random.rand(10^12)}"
61
- else
62
- idCache = d.idCache
63
- end
64
- val_to_cache << [type, idCache, d]
65
- end
66
- else
67
- id = [id] unless id.is_a? Array
68
- if data.length == id.length
69
- for i in 0...id.length
70
- type = data[i].class.to_s
71
- type.slice! "Arango"
72
- type = "Other" if @max[type].nil?
73
- val_to_cache << [type, id[i], data[i]]
74
- end
75
- else
76
- return "Id should be a String or an Array with the same size of the Data Array"
77
- end
78
- end
79
-
80
- val_to_cache.each do |val|
81
- @cache[val[0]][val[1]] = val[2]
82
- @cache[val[0]].shift if @cache[val[0]].length > @max[val[0]]
83
- end
84
-
85
- val_to_cache
86
- end
87
-
88
- def uncache(type: nil, id: nil, data: nil)
89
- if id.nil? && data.nil? && !type.nil?
90
- val_to_uncache = @cache[type].map{|k,v| v}
91
- val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
92
- return val_to_uncache
93
- end
94
-
95
- val_to_uncache = []
96
- unless data.nil?
97
- data = [data] unless data.is_a? Array
98
- data.each do |d|
99
- type = d.class.to_s
100
- type.slice! "Arango"
101
- next if @max[type].nil? || type == "Other"
102
- idCache = d.idCache
103
- val_to_uncache << [type, idCache]
104
- end
105
- end
106
- unless type.nil? || id.nil?
107
- id = [id] unless id.is_a? Array
108
- if type.is_a? Array
109
- if type.length == id.length
110
- for i in 0...type.length
111
- val_to_uncache << [type[i], id[i]]
112
- end
113
- else
114
- return "Type should be a String or an Array with the same size of the Id Array"
115
- end
116
- elsif type.is_a? String
117
- id.each do |idCache|
118
- val_to_uncache << [type, idCache]
119
- end
120
- else
121
- return "Type should be a String or an Array with the same size of the Id Array"
122
- end
123
- end
124
- val_to_uncache = val_to_uncache.map{|val| @cache[val[0]][val[1]]}
125
- val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
126
- val_to_uncache
127
- end
128
-
129
- def clear(type: nil, id: nil, data: nil)
130
- if type.nil? && id.nil? && data.nil?
131
- @cache = { "Database" => {}, "Collection" => {}, "Document" => {}, "Graph" => {}, "Vertex" => {}, "Edge" => {}, "Index" => {}, "Query" => {},"User" => {}, "Traversal" => {}, "Transaction" => {} }
132
- return true
133
- end
134
-
135
- if !type.nil? && id.nil? && data.nil?
136
- @cache[type] = {}
137
- return true
138
- end
139
-
140
- val_to_clear = []
141
- unless data.nil?
142
- data = [data] unless data.is_a? Array
143
- data.each do |d|
144
- type = d.class.to_s
145
- type.slice! "Arango"
146
- next if @max[type].nil? || type == "Other"
147
- val_to_clear << [type, d.idCache]
148
- end
149
- end
150
-
151
- unless type.nil? || id.nil?
152
- id = [id] unless id.is_a? Array
153
- if type.is_a? Array
154
- if type.length == id.length
155
- for i in 0...type.length
156
- val_to_clear << [type[i], id[i]]
157
- end
158
- else
159
- return "Type should be a String or an Array with the same size of the Id Array"
160
- end
161
- elsif type.is_a? String
162
- id.each do |idCache|
163
- val_to_clear << [type, idCache]
164
- end
165
- else
166
- return "Type should be a String or an Array with the same size of the Id Array"
167
- end
168
- end
169
-
170
- val_to_clear.each{|val| @cache[val[0]].delete(val[1])}
171
- true
172
- end
173
- end
174
- end
1
+ # ==== CACHE ====
2
+
3
+ class ArangoCache
4
+ @max = {
5
+ "Database" => 1,
6
+ "Collection" => 20,
7
+ "Document" => 200,
8
+ "Graph" => 1,
9
+ "Vertex" => 50,
10
+ "Edge" => 100,
11
+ "Index" => 20,
12
+ "AQL" => 100,
13
+ "User" => 50,
14
+ "Task" => 20,
15
+ "Traversal" => 20,
16
+ "Transaction" => 20,
17
+ "Other" => 100
18
+ }
19
+ @cache = {
20
+ "Database" => {},
21
+ "Collection" => {},
22
+ "Document" => {},
23
+ "Graph" => {},
24
+ "Vertex" => {},
25
+ "Edge" => {},
26
+ "Index" => {},
27
+ "AQL" => {},
28
+ "User" => {},
29
+ "Task" => {},
30
+ "Traversal" => {},
31
+ "Transaction" => {},
32
+ "Other" => {}
33
+ }
34
+
35
+ class << self
36
+ attr_accessor :max
37
+
38
+ def max(type:, val:)
39
+ return nil if @max[type].nil?
40
+ while @cache[type].length > val
41
+ @cache[type].shift
42
+ end
43
+ @max[type] = val
44
+ end
45
+
46
+ def retrieve
47
+ @cache
48
+ end
49
+
50
+ def cache(id: nil, data:)
51
+ val_to_cache = []
52
+ data = [data] unless data.is_a? Array
53
+
54
+ if id.nil?
55
+ data.each do |d|
56
+ type = d.class.to_s
57
+ type.slice! "Arango"
58
+ if @max[type].nil?
59
+ type = "Other"
60
+ idCache = "OTH_#{d.class.to_s}_#{Random.rand(10^12)}"
61
+ else
62
+ idCache = d.idCache
63
+ end
64
+ val_to_cache << [type, idCache, d]
65
+ end
66
+ else
67
+ id = [id] unless id.is_a? Array
68
+ if data.length == id.length
69
+ for i in 0...id.length
70
+ type = data[i].class.to_s
71
+ type.slice! "Arango"
72
+ type = "Other" if @max[type].nil?
73
+ val_to_cache << [type, id[i], data[i]]
74
+ end
75
+ else
76
+ return "Id should be a String or an Array with the same size of the Data Array"
77
+ end
78
+ end
79
+
80
+ val_to_cache.each do |val|
81
+ @cache[val[0]][val[1]] = val[2]
82
+ @cache[val[0]].shift if @cache[val[0]].length > @max[val[0]]
83
+ end
84
+
85
+ val_to_cache
86
+ end
87
+
88
+ def uncache(type: nil, id: nil, data: nil)
89
+ if id.nil? && data.nil? && !type.nil?
90
+ val_to_uncache = @cache[type].map{|k,v| v}
91
+ val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
92
+ return val_to_uncache
93
+ end
94
+
95
+ val_to_uncache = []
96
+ unless data.nil?
97
+ data = [data] unless data.is_a? Array
98
+ data.each do |d|
99
+ type = d.class.to_s
100
+ type.slice! "Arango"
101
+ next if @max[type].nil? || type == "Other"
102
+ idCache = d.idCache
103
+ val_to_uncache << [type, idCache]
104
+ end
105
+ end
106
+ unless type.nil? || id.nil?
107
+ id = [id] unless id.is_a? Array
108
+ if type.is_a? Array
109
+ if type.length == id.length
110
+ for i in 0...type.length
111
+ val_to_uncache << [type[i], id[i]]
112
+ end
113
+ else
114
+ return "Type should be a String or an Array with the same size of the Id Array"
115
+ end
116
+ elsif type.is_a? String
117
+ id.each do |idCache|
118
+ val_to_uncache << [type, idCache]
119
+ end
120
+ else
121
+ return "Type should be a String or an Array with the same size of the Id Array"
122
+ end
123
+ end
124
+ val_to_uncache = val_to_uncache.map{|val| @cache[val[0]][val[1]]}
125
+ val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
126
+ val_to_uncache
127
+ end
128
+
129
+ def clear(type: nil, id: nil, data: nil)
130
+ if type.nil? && id.nil? && data.nil?
131
+ @cache = { "Database" => {}, "Collection" => {}, "Document" => {}, "Graph" => {}, "Vertex" => {}, "Edge" => {}, "Index" => {}, "Query" => {},"User" => {}, "Traversal" => {}, "Transaction" => {} }
132
+ return true
133
+ end
134
+
135
+ if !type.nil? && id.nil? && data.nil?
136
+ @cache[type] = {}
137
+ return true
138
+ end
139
+
140
+ val_to_clear = []
141
+ unless data.nil?
142
+ data = [data] unless data.is_a? Array
143
+ data.each do |d|
144
+ type = d.class.to_s
145
+ type.slice! "Arango"
146
+ next if @max[type].nil? || type == "Other"
147
+ val_to_clear << [type, d.idCache]
148
+ end
149
+ end
150
+
151
+ unless type.nil? || id.nil?
152
+ id = [id] unless id.is_a? Array
153
+ if type.is_a? Array
154
+ if type.length == id.length
155
+ for i in 0...type.length
156
+ val_to_clear << [type[i], id[i]]
157
+ end
158
+ else
159
+ return "Type should be a String or an Array with the same size of the Id Array"
160
+ end
161
+ elsif type.is_a? String
162
+ id.each do |idCache|
163
+ val_to_clear << [type, idCache]
164
+ end
165
+ else
166
+ return "Type should be a String or an Array with the same size of the Id Array"
167
+ end
168
+ end
169
+
170
+ val_to_clear.each{|val| @cache[val[0]].delete(val[1])}
171
+ true
172
+ end
173
+ end
174
+ end