Class: ArangoGraph
- Inherits:
-
ArangoServer
- Object
- ArangoServer
- ArangoGraph
- Defined in:
- lib/ArangoRB_Gra.rb
Overview
GRAPH ====
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#edgeDefinitions ⇒ Object
readonly
Returns the value of attribute edgeDefinitions.
-
#graph ⇒ Object
(also: #name)
readonly
Returns the value of attribute graph.
-
#idCache ⇒ Object
readonly
Returns the value of attribute idCache.
-
#orphanCollections ⇒ Object
readonly
Returns the value of attribute orphanCollections.
Instance Method Summary collapse
-
#addEdgeCollection(collection:, from:, to:, replace: false) ⇒ Object
TESTED.
-
#addVertexCollection(collection:) ⇒ Object
TESTED.
-
#create ⇒ Object
POST ===.
-
#destroy ⇒ Object
DELETE ===.
-
#edgeCollections ⇒ Object
EDGE COLLECTION ===.
-
#initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: []) ⇒ ArangoGraph
constructor
TESTED.
-
#removeEdgeCollection(collection:) ⇒ Object
TESTED.
-
#removeVertexCollection(collection:) ⇒ Object
TESTED.
-
#replaceEdgeCollection(collection:, from:, to:) ⇒ Object
TESTED.
-
#retrieve ⇒ Object
GET ===.
-
#to_hash ⇒ Object
(also: #to_h)
RETRIEVE ===.
-
#vertexCollections ⇒ Object
VERTEX COLLECTION ===.
Methods inherited from ArangoServer
address, async, async=, batch, cancelAsync, changePropertyWAL, checkPort, cluster, cluster=, clusterRoundtrip, clusterStatistics, collection, collection=, createDumpBatch, database, database=, databaseVersion, databases, default_server, destroyAllAsync, destroyAsync, destroyCluster, destroyDumpBatch, destroyExpiredAsync, echo, endpoints, execute, executeCluster, executeClusterHead, executeClusterPut, fetchAsync, flushWAL, graph, graph=, log, pendingAsync, prolongDumpBatch, propertyWAL, reload, request, restart, retrieveAsync, retrieveDoneAsync, retrievePendingAsync, return_result, return_result_async, role, server, serverId, shutdown, sleep, statistics, tasks, test, time, transactions, updateCluster, user, user=, username, users, verbose, verbose=, version
Constructor Details
#initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: []) ⇒ ArangoGraph
TESTED
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ArangoRB_Gra.rb', line 4 def initialize(graph: @@graph, database: @@database, edgeDefinitions: [], orphanCollections: []) # TESTED if database.is_a?(String) @database = database elsif database.is_a?(ArangoDatabase) @database = database.database else raise "database should be a String or an ArangoDatabase instance, not a #{database.class}" end if graph.is_a?(String) @graph = graph elsif database.is_a?(ArangoGraph) @graph = graph.graph else raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}" end if edgeDefinitions.is_a?(Array) @edgeDefinitions = edgeDefinitions else raise "edgeDefinitions should be an Array, not a #{edgeDefinitions.class}" end if orphanCollections.is_a?(Array) @orphanCollections = orphanCollections else raise "orphanCollections should be an Array, not a #{orphanCollections.class}" end @idCache = "GRA_#{@graph}" end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
36 37 38 |
# File 'lib/ArangoRB_Gra.rb', line 36 def database @database end |
#edgeDefinitions ⇒ Object (readonly)
Returns the value of attribute edgeDefinitions.
36 37 38 |
# File 'lib/ArangoRB_Gra.rb', line 36 def edgeDefinitions @edgeDefinitions end |
#graph ⇒ Object (readonly) Also known as: name
Returns the value of attribute graph.
36 37 38 |
# File 'lib/ArangoRB_Gra.rb', line 36 def graph @graph end |
#idCache ⇒ Object (readonly)
Returns the value of attribute idCache.
36 37 38 |
# File 'lib/ArangoRB_Gra.rb', line 36 def idCache @idCache end |
#orphanCollections ⇒ Object (readonly)
Returns the value of attribute orphanCollections.
36 37 38 |
# File 'lib/ArangoRB_Gra.rb', line 36 def orphanCollections @orphanCollections end |
Instance Method Details
#addEdgeCollection(collection:, from:, to:, replace: false) ⇒ Object
TESTED
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ArangoRB_Gra.rb', line 147 def addEdgeCollection(collection:, from:, to:, replace: false) # TESTED from = from.is_a?(String) ? [from] : from.is_a?(ArangoCollection) ? [from.collection] : from to = to.is_a?(String) ? [to] : to.is_a?(ArangoCollection) ? [to.collection] : to body = {} collection = collection.is_a?(String) ? collection : collection.collection body["collection"] = collection body["from"] = from.map{|f| f.is_a?(String) ? f : f.id } body["to"] = to.map{|t| t.is_a?(String) ? t : t.id } request = @@request.merge({ :body => body.to_json }) if replace result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", request) else result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge", request) end return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose unless result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] end result else return result["errorMessage"] if result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end end |
#addVertexCollection(collection:) ⇒ Object
TESTED
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ArangoRB_Gra.rb', line 103 def addVertexCollection(collection:) # TESTED collection = collection.is_a?(String) ? collection : collection.collection body = { "collection" => collection }.to_json request = @@request.merge({ :body => body }) result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/vertex", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose @orphanCollections << collection unless result["error"] result else return result["errorMessage"] if result["error"] @orphanCollections << collection self end end |
#create ⇒ Object
POST ===
73 74 75 76 77 78 79 80 81 |
# File 'lib/ArangoRB_Gra.rb', line 73 def create # TESTED body = { "name" => @graph, "edgeDefinitions" => @edgeDefinitions, "orphanCollections" => @orphanCollections } request = @@request.merge({ :body => body.to_json }) result = self.class.post("/_db/#{@database}/_api/gharial", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : self end |
#destroy ⇒ Object
DELETE ===
85 86 87 88 89 90 91 |
# File 'lib/ArangoRB_Gra.rb', line 85 def destroy # TESTED result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : true end |
#edgeCollections ⇒ Object
EDGE COLLECTION ===
139 140 141 142 143 144 145 |
# File 'lib/ArangoRB_Gra.rb', line 139 def edgeCollections # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)} end |
#removeEdgeCollection(collection:) ⇒ Object
TESTED
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ArangoRB_Gra.rb', line 182 def removeEdgeCollection(collection:) # TESTED collection = collection.is_a?(String) ? collection : collection.collection result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose unless result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] end result else return result["errorMessage"] if result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end end |
#removeVertexCollection(collection:) ⇒ Object
TESTED
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ArangoRB_Gra.rb', line 121 def removeVertexCollection(collection:) # TESTED collection = collection.is_a?(String) ? collection : collection.collection result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{collection}", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose @orphanCollections -= [collection] unless result["error"] result else return result["errorMessage"] if result["error"] @orphanCollections -= [collection] self end end |
#replaceEdgeCollection(collection:, from:, to:) ⇒ Object
TESTED
178 179 180 |
# File 'lib/ArangoRB_Gra.rb', line 178 def replaceEdgeCollection(collection:, from:, to:) # TESTED self.addEdgeCollection(collection: collection, from: from, to: to, replace: true) end |
#retrieve ⇒ Object
GET ===
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ArangoRB_Gra.rb', line 59 def retrieve # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response return result if @@verbose return result["errorMessage"] if result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end |
#to_hash ⇒ Object Also known as: to_h
RETRIEVE ===
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ArangoRB_Gra.rb', line 41 def to_hash { "graph" => @graph, "collection" => @collection, "database" => @database, "edgeDefinitions" => @edgeDefinitions, "orphanCollections" => @orphanCollections, "idCache" => @idCache }.delete_if{|k,v| v.nil?} end |
#vertexCollections ⇒ Object
VERTEX COLLECTION ===
95 96 97 98 99 100 101 |
# File 'lib/ArangoRB_Gra.rb', line 95 def vertexCollections # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)} end |