arangorb 1.4.1 → 2.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 +20 -18
- data/Gemfile +3 -0
- data/README.md +1079 -908
- data/lib/AQL.rb +155 -0
- data/lib/Batch.rb +97 -0
- data/lib/Cache.rb +71 -0
- data/lib/Collection.rb +852 -0
- data/lib/Database.rb +417 -0
- data/lib/Document.rb +346 -0
- data/lib/Edge.rb +104 -0
- data/lib/Error.rb +125 -0
- data/lib/Foxx.rb +277 -0
- data/lib/Graph.rb +325 -0
- data/lib/Index.rb +126 -0
- data/lib/Replication.rb +235 -0
- data/lib/Request.rb +143 -0
- data/lib/Server.rb +466 -0
- data/lib/Task.rb +120 -0
- data/lib/Transaction.rb +115 -0
- data/lib/Traversal.rb +224 -0
- data/lib/User.rb +197 -0
- data/lib/Vertex.rb +127 -0
- data/lib/View.rb +151 -0
- data/lib/arangorb.rb +23 -15
- data/lib/helpers/Error.rb +28 -0
- data/lib/helpers/Return.rb +53 -0
- metadata +64 -45
- data/lib/ArangoRB_AQL.rb +0 -181
- data/lib/ArangoRB_Cache.rb +0 -174
- data/lib/ArangoRB_Col.rb +0 -526
- data/lib/ArangoRB_DB.rb +0 -363
- data/lib/ArangoRB_Doc.rb +0 -319
- data/lib/ArangoRB_Edg.rb +0 -184
- data/lib/ArangoRB_Gra.rb +0 -201
- data/lib/ArangoRB_Index.rb +0 -135
- data/lib/ArangoRB_Replication.rb +0 -261
- data/lib/ArangoRB_Ser.rb +0 -446
- data/lib/ArangoRB_Task.rb +0 -129
- data/lib/ArangoRB_Tra.rb +0 -169
- data/lib/ArangoRB_Tran.rb +0 -68
- data/lib/ArangoRB_User.rb +0 -157
- data/lib/ArangoRB_Ver.rb +0 -162
- data/spec/arangoRB_helper.rb +0 -4
- data/spec/arangoRestart_helper.rb +0 -14
- data/spec/arangorb-1.3.0.gem +0 -0
- data/spec/lib/0.1.0/arangoAQL_helper.rb +0 -64
- data/spec/lib/0.1.0/arangoC_helper.rb +0 -170
- data/spec/lib/0.1.0/arangoDB_helper.rb +0 -119
- data/spec/lib/0.1.0/arangoDoc_helper.rb +0 -79
- data/spec/lib/0.1.0/arangoE_helper.rb +0 -50
- data/spec/lib/0.1.0/arangoG_helper.rb +0 -78
- data/spec/lib/0.1.0/arangoS_helper.rb +0 -37
- data/spec/lib/0.1.0/arangoT_helper.rb +0 -48
- data/spec/lib/0.1.0/arangoV_helper.rb +0 -65
- data/spec/lib/1.0.0/arangoC_helper.rb +0 -73
- data/spec/lib/1.0.0/arangoDB_helper.rb +0 -48
- data/spec/lib/1.0.0/arangoI_helper.rb +0 -43
- data/spec/lib/1.0.0/arangoS_helper.rb +0 -192
- data/spec/lib/1.0.0/arangoTa_helper.rb +0 -49
- data/spec/lib/1.0.0/arangoTr_helper.rb +0 -15
- data/spec/lib/1.0.0/arangoU_helper.rb +0 -72
- data/spec/lib/1.1.0/arangoRB_helper.rb +0 -144
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +0 -19
- data/spec/lib/1.2.0/arangoCache_helper.rb +0 -66
- data/spec/lib/1.3.0/arangoHash_helper.rb +0 -30
- data/spec/lib/arangoRB_0.1.0_helper.rb +0 -9
- data/spec/lib/arangoRB_1.0.0_helper.rb +0 -6
- data/spec/lib/arangoRB_1.1.0_helper.rb +0 -2
- data/spec/lib/arangoRB_1.2.0_helper.rb +0 -2
- data/spec/spec_helper.rb +0 -42
data/lib/arangorb.rb
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
require "httparty"
|
2
|
-
|
3
|
-
|
4
|
-
require_relative "
|
5
|
-
require_relative "
|
6
|
-
require_relative "
|
7
|
-
require_relative "
|
8
|
-
require_relative "
|
9
|
-
require_relative "
|
10
|
-
require_relative "
|
11
|
-
require_relative "
|
12
|
-
require_relative "
|
13
|
-
require_relative "
|
14
|
-
require_relative "
|
15
|
-
require_relative "
|
16
|
-
require_relative "
|
2
|
+
require "oj"
|
3
|
+
require "connection_pool"
|
4
|
+
require_relative "helpers/Error"
|
5
|
+
require_relative "helpers/Return"
|
6
|
+
require_relative "AQL"
|
7
|
+
require_relative "Batch"
|
8
|
+
require_relative "Server"
|
9
|
+
require_relative "Collection"
|
10
|
+
require_relative "Database"
|
11
|
+
require_relative "Document"
|
12
|
+
require_relative "Edge"
|
13
|
+
require_relative "Error"
|
14
|
+
require_relative "Foxx"
|
15
|
+
require_relative "Graph"
|
16
|
+
require_relative "Index"
|
17
|
+
require_relative "Task"
|
18
|
+
require_relative "Transaction"
|
19
|
+
require_relative "Traversal"
|
20
|
+
require_relative "User"
|
21
|
+
require_relative "Vertex"
|
22
|
+
require_relative "View"
|
23
|
+
require_relative "Cache"
|
24
|
+
require_relative "Request"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Arango
|
2
|
+
module Helper_Error
|
3
|
+
def satisfy_class?(object, classes=[String], array=false)
|
4
|
+
if array
|
5
|
+
object = [object] unless object.is_a?(Array)
|
6
|
+
object.each do |obj|
|
7
|
+
satisfy_class?(obj, classes, false)
|
8
|
+
end
|
9
|
+
else
|
10
|
+
return if classes.include?(object.class)
|
11
|
+
name ||= object.object_id.to_s
|
12
|
+
raise Arango::Error.new err: :wrong_class, data: {"wrong_value": name,
|
13
|
+
"wrong_class": object.class.to_s, "expected_class": classes.to_s}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def satisfy_category?(object, list)
|
18
|
+
return if list.include?(object)
|
19
|
+
name = object.object_id.to_s
|
20
|
+
raise Arango::Error.new err: :wrong_element, data: {"wrong_attribute": name,
|
21
|
+
"wrong_value": object, "list": list}
|
22
|
+
end
|
23
|
+
|
24
|
+
def warning_deprecated(warning, name)
|
25
|
+
puts "ARANGORB WARNING: #{name} function is deprecated" if warning
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Arango
|
2
|
+
module Helper_Return
|
3
|
+
def return_directly?(result)
|
4
|
+
return @server.async != false || @server.return_output
|
5
|
+
return result == true
|
6
|
+
end
|
7
|
+
|
8
|
+
def return_element(result)
|
9
|
+
return result if @server.async != false
|
10
|
+
assign_attributes(result)
|
11
|
+
return return_directly?(result) ? result : self
|
12
|
+
end
|
13
|
+
|
14
|
+
def return_delete(result)
|
15
|
+
return result if @server.async != false
|
16
|
+
return return_directly?(result) ? result : true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Arango
|
22
|
+
module Server_Return
|
23
|
+
def server=(server)
|
24
|
+
satisfy_class?(server, [Arango::Server])
|
25
|
+
@server = server
|
26
|
+
end
|
27
|
+
alias assign_server server=
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Arango
|
32
|
+
module Database_Return
|
33
|
+
def database=(database)
|
34
|
+
satisfy_class?(database, [Arango::Database])
|
35
|
+
@database = database
|
36
|
+
@server = @database.server
|
37
|
+
end
|
38
|
+
alias assign_database database=
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Arango
|
43
|
+
module Collection_Return
|
44
|
+
def collection=(collection)
|
45
|
+
satisfy_class?(collection, [Arango::Collection])
|
46
|
+
@collection = collection
|
47
|
+
@graph = @collection.graph
|
48
|
+
@database = @collection.database
|
49
|
+
@server = @database.server
|
50
|
+
end
|
51
|
+
alias assign_collection collection=
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arangorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -30,6 +30,46 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.14.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: oj
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.6.11
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.6.11
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.6.11
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.6.11
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: connection_pool
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.2.2
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.2.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.2.2
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.2.2
|
33
73
|
description: Ruby driver for ArangoDB's HTTP API
|
34
74
|
email:
|
35
75
|
- stefano@seluxit.com
|
@@ -41,50 +81,29 @@ files:
|
|
41
81
|
- Gemfile
|
42
82
|
- LICENSE
|
43
83
|
- README.md
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
53
|
-
- lib/
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
84
|
+
- lib/AQL.rb
|
85
|
+
- lib/Batch.rb
|
86
|
+
- lib/Cache.rb
|
87
|
+
- lib/Collection.rb
|
88
|
+
- lib/Database.rb
|
89
|
+
- lib/Document.rb
|
90
|
+
- lib/Edge.rb
|
91
|
+
- lib/Error.rb
|
92
|
+
- lib/Foxx.rb
|
93
|
+
- lib/Graph.rb
|
94
|
+
- lib/Index.rb
|
95
|
+
- lib/Replication.rb
|
96
|
+
- lib/Request.rb
|
97
|
+
- lib/Server.rb
|
98
|
+
- lib/Task.rb
|
99
|
+
- lib/Transaction.rb
|
100
|
+
- lib/Traversal.rb
|
101
|
+
- lib/User.rb
|
102
|
+
- lib/Vertex.rb
|
103
|
+
- lib/View.rb
|
59
104
|
- lib/arangorb.rb
|
60
|
-
-
|
61
|
-
-
|
62
|
-
- spec/arangorb-1.3.0.gem
|
63
|
-
- spec/lib/0.1.0/arangoAQL_helper.rb
|
64
|
-
- spec/lib/0.1.0/arangoC_helper.rb
|
65
|
-
- spec/lib/0.1.0/arangoDB_helper.rb
|
66
|
-
- spec/lib/0.1.0/arangoDoc_helper.rb
|
67
|
-
- spec/lib/0.1.0/arangoE_helper.rb
|
68
|
-
- spec/lib/0.1.0/arangoG_helper.rb
|
69
|
-
- spec/lib/0.1.0/arangoS_helper.rb
|
70
|
-
- spec/lib/0.1.0/arangoT_helper.rb
|
71
|
-
- spec/lib/0.1.0/arangoV_helper.rb
|
72
|
-
- spec/lib/1.0.0/arangoC_helper.rb
|
73
|
-
- spec/lib/1.0.0/arangoDB_helper.rb
|
74
|
-
- spec/lib/1.0.0/arangoI_helper.rb
|
75
|
-
- spec/lib/1.0.0/arangoS_helper.rb
|
76
|
-
- spec/lib/1.0.0/arangoTa_helper.rb
|
77
|
-
- spec/lib/1.0.0/arangoTr_helper.rb
|
78
|
-
- spec/lib/1.0.0/arangoU_helper.rb
|
79
|
-
- spec/lib/1.1.0/arangoRB_helper.rb
|
80
|
-
- spec/lib/1.1.0/arangoRB_walks_helper.rb
|
81
|
-
- spec/lib/1.2.0/arangoCache_helper.rb
|
82
|
-
- spec/lib/1.3.0/arangoHash_helper.rb
|
83
|
-
- spec/lib/arangoRB_0.1.0_helper.rb
|
84
|
-
- spec/lib/arangoRB_1.0.0_helper.rb
|
85
|
-
- spec/lib/arangoRB_1.1.0_helper.rb
|
86
|
-
- spec/lib/arangoRB_1.2.0_helper.rb
|
87
|
-
- spec/spec_helper.rb
|
105
|
+
- lib/helpers/Error.rb
|
106
|
+
- lib/helpers/Return.rb
|
88
107
|
homepage: https://github.com/StefanoMartin/ArangoRB
|
89
108
|
licenses:
|
90
109
|
- MIT
|
data/lib/ArangoRB_AQL.rb
DELETED
@@ -1,181 +0,0 @@
|
|
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
|
data/lib/ArangoRB_Cache.rb
DELETED
@@ -1,174 +0,0 @@
|
|
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
|