Class: ArangoTransaction
- Inherits:
-
ArangoServer
- Object
- ArangoServer
- ArangoTransaction
- Defined in:
- lib/ArangoRB_Tran.rb
Overview
TRANSACTION ===
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#idCache ⇒ Object
readonly
Returns the value of attribute idCache.
-
#lockTimeout ⇒ Object
readonly
Returns the value of attribute lockTimeout.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#waitForSync ⇒ Object
readonly
Returns the value of attribute waitForSync.
Instance Method Summary collapse
- #collections ⇒ Object
- #database ⇒ Object
-
#execute ⇒ Object
TESTED.
-
#initialize(database: @@database, action:, write: [], read: [], params: nil, lockTimeout: nil, waitForSync: nil) ⇒ ArangoTransaction
constructor
TESTED.
-
#to_hash ⇒ Object
(also: #to_h)
RETRIEVE ###.
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(database: @@database, action:, write: [], read: [], params: nil, lockTimeout: nil, waitForSync: nil) ⇒ ArangoTransaction
TESTED
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ArangoRB_Tran.rb', line 4 def initialize(database: @@database, action:, write: [], read: [], params: nil, lockTimeout: nil, waitForSync: nil) # 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 @action = action @collections = {} @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] : [] @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] : [] @params = params @lockTimeout = lockTimeout @waitForSync = waitForSync @result = nil @idCache = "AT_#{@database}_#{Random.rand(0..10^12)}" end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
23 24 25 |
# File 'lib/ArangoRB_Tran.rb', line 23 def action @action end |
#idCache ⇒ Object (readonly)
Returns the value of attribute idCache.
23 24 25 |
# File 'lib/ArangoRB_Tran.rb', line 23 def idCache @idCache end |
#lockTimeout ⇒ Object (readonly)
Returns the value of attribute lockTimeout.
23 24 25 |
# File 'lib/ArangoRB_Tran.rb', line 23 def lockTimeout @lockTimeout end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
23 24 25 |
# File 'lib/ArangoRB_Tran.rb', line 23 def params @params end |
#waitForSync ⇒ Object (readonly)
Returns the value of attribute waitForSync.
23 24 25 |
# File 'lib/ArangoRB_Tran.rb', line 23 def waitForSync @waitForSync end |
Instance Method Details
#collections ⇒ Object
41 42 43 44 45 46 |
# File 'lib/ArangoRB_Tran.rb', line 41 def collections result = {} result["write"] = @collections["write"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["write"].nil? result["read"] = @collections["read"].map{|x| ArangoCollection.new(database: @database, collection: x)} unless @collections["read"].nil? result end |
#database ⇒ Object
48 49 50 |
# File 'lib/ArangoRB_Tran.rb', line 48 def database ArangoDatabase.new(database: @database) end |
#execute ⇒ Object
TESTED
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ArangoRB_Tran.rb', line 52 def execute # TESTED body = { "action" => @action, "collections" => @collections, "params" => @params, "lockTimeout" => @lockTimeout, "waitForSync" => @waitForSync }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) result = self.class.post("/_db/#{@database}/_api/transaction", request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @result = result["result"] unless result["error"] @@verbose ? result : result["error"] ? {"message": result["errorMessage"], "stacktrace": result["stacktrace"]} : result["result"] end |
#to_hash ⇒ Object Also known as: to_h
RETRIEVE ###
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ArangoRB_Tran.rb', line 27 def to_hash { "database" => @database, "action" => @action, "collections" => @collections, "result" => @result, "params" => @params, "lockTimeout" => @lockTimeout, "waitForSync" => @waitForSync, "idCache" => @idCache }.delete_if{|k,v| v.nil?} end |