Class: Scalaroid::JSONReqList
- Inherits:
-
Object
- Object
- Scalaroid::JSONReqList
- Defined in:
- lib/scalaroid/json_req_list.rb
Overview
Request list for use with Transaction.req_list()
Direct Known Subclasses
Instance Method Summary collapse
-
#add_add_del_on_list(key, to_add, to_remove) ⇒ Object
Adds a add_del_on_list operation to the request list.
-
#add_add_on_nr(key, to_add) ⇒ Object
Adds a add_on_nr operation to the request list.
-
#add_commit ⇒ Object
Adds a commit operation to the request list.
-
#add_read(key) ⇒ Object
Adds a read operation to the request list.
-
#add_test_and_set(key, old_value, new_value) ⇒ Object
Adds a test_and_set operation to the request list.
-
#add_write(key, value, binary = false) ⇒ Object
Adds a write operation to the request list.
-
#concat(other) ⇒ Object
Adds all requests of the other request list to the end of this list.
-
#get_requests ⇒ Object
Gets the collected requests.
-
#initialize(other = nil) ⇒ JSONReqList
constructor
Create a new object using a JSON connection.
-
#is_commit ⇒ Object
Returns whether the transactions contains a commit or not.
-
#is_empty ⇒ Object
Checks whether the request list is empty.
-
#size ⇒ Object
Gets the number of requests in the list.
Constructor Details
#initialize(other = nil) ⇒ JSONReqList
Create a new object using a JSON connection.
5 6 7 8 9 10 11 |
# File 'lib/scalaroid/json_req_list.rb', line 5 def initialize(other = nil) @requests = [] @is_commit = false if not other == nil concat(other) end end |
Instance Method Details
#add_add_del_on_list(key, to_add, to_remove) ⇒ Object
Adds a add_del_on_list operation to the request list.
32 33 34 35 36 37 38 |
# File 'lib/scalaroid/json_req_list.rb', line 32 def add_add_del_on_list(key, to_add, to_remove) if (@is_commit) raise RuntimeError.new('No further request supported after a commit!') end @requests << {'add_del_on_list' => {'key' => key, 'add' => to_add, 'del'=> to_remove}} self end |
#add_add_on_nr(key, to_add) ⇒ Object
Adds a add_on_nr operation to the request list.
41 42 43 44 45 46 47 |
# File 'lib/scalaroid/json_req_list.rb', line 41 def add_add_on_nr(key, to_add) if (@is_commit) raise RuntimeError.new('No further request supported after a commit!') end @requests << {'add_on_nr' => {key => to_add}} self end |
#add_commit ⇒ Object
Adds a commit operation to the request list.
61 62 63 64 65 66 67 68 |
# File 'lib/scalaroid/json_req_list.rb', line 61 def add_commit if (@is_commit) raise RuntimeError.new('Only one commit per request list allowed!') end @requests << {'commit' => ''} @is_commit = true self end |
#add_read(key) ⇒ Object
Adds a read operation to the request list.
14 15 16 17 18 19 20 |
# File 'lib/scalaroid/json_req_list.rb', line 14 def add_read(key) if (@is_commit) raise RuntimeError.new('No further request supported after a commit!') end @requests << {'read' => key} self end |
#add_test_and_set(key, old_value, new_value) ⇒ Object
Adds a test_and_set operation to the request list.
50 51 52 53 54 55 56 57 58 |
# File 'lib/scalaroid/json_req_list.rb', line 50 def add_test_and_set(key, old_value, new_value) if (@is_commit) raise RuntimeError.new('No further request supported after a commit!') end @requests << {'test_and_set' => {'key' => key, 'old' => JSONConnection.encode_value(old_value, false), 'new' => JSONConnection.encode_value(new_value, false)}} self end |
#add_write(key, value, binary = false) ⇒ Object
Adds a write operation to the request list.
23 24 25 26 27 28 29 |
# File 'lib/scalaroid/json_req_list.rb', line 23 def add_write(key, value, binary = false) if (@is_commit) raise RuntimeError.new('No further request supported after a commit!') end @requests << {'write' => {key => JSONConnection.encode_value(value, binary)}} self end |
#concat(other) ⇒ Object
Adds all requests of the other request list to the end of this list.
91 92 93 94 |
# File 'lib/scalaroid/json_req_list.rb', line 91 def concat(other) @requests.concat(other.get_requests()) self end |
#get_requests ⇒ Object
Gets the collected requests.
71 72 73 |
# File 'lib/scalaroid/json_req_list.rb', line 71 def get_requests @requests end |
#is_commit ⇒ Object
Returns whether the transactions contains a commit or not.
76 77 78 |
# File 'lib/scalaroid/json_req_list.rb', line 76 def is_commit() @is_commit end |
#is_empty ⇒ Object
Checks whether the request list is empty.
81 82 83 |
# File 'lib/scalaroid/json_req_list.rb', line 81 def is_empty() @requests.empty? end |
#size ⇒ Object
Gets the number of requests in the list.
86 87 88 |
# File 'lib/scalaroid/json_req_list.rb', line 86 def size() @requests.length end |