Class: Imperium::Transaction
- Inherits:
-
Object
- Object
- Imperium::Transaction
- Defined in:
- lib/imperium/transaction.rb
Overview
A Transaction support for KV API
Instance Method Summary collapse
-
#add_operation(verb, key, value: nil, flags: nil, index: nil, session_id: nil) ⇒ Object
List of operations to perform inside the atomic transaction.
-
#body ⇒ Object
Get JSON object for operations.
-
#initialize ⇒ Transaction
constructor
Initaialize a new transaction containing an array of operations.
-
#set(key, value, flags: nil) ⇒ Object
Set or Put a key value pair.
Constructor Details
#initialize ⇒ Transaction
Initaialize a new transaction containing an array of operations
6 7 8 |
# File 'lib/imperium/transaction.rb', line 6 def initialize @operations = [] end |
Instance Method Details
#add_operation(verb, key, value: nil, flags: nil, index: nil, session_id: nil) ⇒ Object
Returns list of operations to perform inside the atomic transaction.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/imperium/transaction.rb', line 36 def add_operation(verb, key, value: nil, flags: nil, index: nil, session_id: nil) kv = { 'Verb' => verb, 'Key' => key } kv['Value'] = Base64.encode64(value) if value kv['Flags'] = flags if flags kv['Index'] = index if index kv['Session'] = session_id if session_id @operations << { 'KV' => kv } end |
#body ⇒ Object
Get JSON object for operations
19 20 21 |
# File 'lib/imperium/transaction.rb', line 19 def body @operations.to_json end |
#set(key, value, flags: nil) ⇒ Object
Set or Put a key value pair
12 13 14 |
# File 'lib/imperium/transaction.rb', line 12 def set(key, value, flags: nil) add_operation('set', key, value: value, flags: flags) end |