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
readonly
Returns the value of attribute graph.
-
#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 ===.
-
#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 |
# 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 end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
34 35 36 |
# File 'lib/ArangoRB_Gra.rb', line 34 def database @database end |
#edgeDefinitions ⇒ Object (readonly)
Returns the value of attribute edgeDefinitions.
34 35 36 |
# File 'lib/ArangoRB_Gra.rb', line 34 def edgeDefinitions @edgeDefinitions end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
34 35 36 |
# File 'lib/ArangoRB_Gra.rb', line 34 def graph @graph end |
#orphanCollections ⇒ Object (readonly)
Returns the value of attribute orphanCollections.
34 35 36 |
# File 'lib/ArangoRB_Gra.rb', line 34 def orphanCollections @orphanCollections end |
Instance Method Details
#addEdgeCollection(collection:, from:, to:, replace: false) ⇒ Object
TESTED
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 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ArangoRB_Gra.rb', line 150 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 if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response if @@verbose unless result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] end result else if result["error"] result["errorMessage"] else @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end end end end |
#addVertexCollection(collection:) ⇒ Object
TESTED
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ArangoRB_Gra.rb', line 96 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) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response if @@verbose result else if result["error"] result["errorMessage"] else @orphanCollections << collection self end end end end |
#create ⇒ Object
POST ===
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ArangoRB_Gra.rb', line 60 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) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : self end end |
#destroy ⇒ Object
DELETE ===
74 75 76 77 78 79 80 81 82 |
# File 'lib/ArangoRB_Gra.rb', line 74 def destroy # TESTED result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : true end end |
#edgeCollections ⇒ Object
EDGE COLLECTION ===
140 141 142 143 144 145 146 147 148 |
# File 'lib/ArangoRB_Gra.rb', line 140 def edgeCollections # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)} end end |
#removeEdgeCollection(collection:) ⇒ Object
TESTED
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/ArangoRB_Gra.rb', line 192 def removeEdgeCollection(collection:) # TESTED collection = collection.is_a?(String) ? collection : collection.collection result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{collection}", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response if @@verbose unless result["error"] @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] end result else if result["error"] result["errorMessage"] else @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end end end end |
#removeVertexCollection(collection:) ⇒ Object
TESTED
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ArangoRB_Gra.rb', line 118 def removeVertexCollection(collection:) # TESTED collection = collection.is_a?(String) ? collection : collection.collection result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/vertex/#{collection}", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response if @@verbose result else if result["error"] result["errorMessage"] else @orphanCollections -= [collection] self end end end end |
#replaceEdgeCollection(collection:, from:, to:) ⇒ Object
TESTED
188 189 190 |
# File 'lib/ArangoRB_Gra.rb', line 188 def replaceEdgeCollection(collection:, from:, to:) # TESTED self.addEdgeCollection(collection: collection, from: from, to: to, replace: true) end |
#retrieve ⇒ Object
GET ===
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ArangoRB_Gra.rb', line 38 def retrieve # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response if @@verbose result else if result["error"] result["errorMessage"] else @edgeDefinitions = result["graph"]["edgeDefinitions"] @orphanCollections = result["graph"]["orphanCollections"] self end end end end |
#vertexCollections ⇒ Object
VERTEX COLLECTION ===
86 87 88 89 90 91 92 93 94 |
# File 'lib/ArangoRB_Gra.rb', line 86 def vertexCollections # TESTED result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/vertex", @@request) if @@async == "store" result.headers["x-arango-async-id"] else result = result.parsed_response @@verbose ? result : result["error"] ? result["errorMessage"] : result["collections"].map{|x| ArangoCollection.new(collection: x)} end end |