class Scalaroid::JSONReqList

Request list for use with Transaction.req_list()

Public Class Methods

new(other = nil) click to toggle source

Create a new object using a JSON connection.

# 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

Public Instance Methods

add_add_del_on_list(key, to_add, to_remove) click to toggle source

Adds a add_del_on_list operation to the request list.

# 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) click to toggle source

Adds a add_on_nr operation to the request list.

# 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() click to toggle source

Adds a commit operation to the request list.

# 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) click to toggle source

Adds a read operation to the request list.

# 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) click to toggle source

Adds a test_and_set operation to the request list.

# 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) click to toggle source

Adds a write operation to the request list.

# 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) click to toggle source

Adds all requests of the other request list to the end of this list.

# File lib/scalaroid/json_req_list.rb, line 91
def concat(other)
  @requests.concat(other.get_requests())
  self
end
get_requests() click to toggle source

Gets the collected requests.

# File lib/scalaroid/json_req_list.rb, line 71
def get_requests
  @requests
end
is_commit() click to toggle source

Returns whether the transactions contains a commit or not.

# File lib/scalaroid/json_req_list.rb, line 76
def is_commit()
  @is_commit
end
is_empty() click to toggle source

Checks whether the request list is empty.

# File lib/scalaroid/json_req_list.rb, line 81
def is_empty()
  @requests.empty?
end
size() click to toggle source

Gets the number of requests in the list.

# File lib/scalaroid/json_req_list.rb, line 86
def size()
  @requests.length
end