class RailsKvsDriver::Lists::List

Attributes

driver_instance[RW]
key[RW]

Public Class Methods

new(driver_instance, key) click to toggle source

initialize list

@param driver_instance [RailsKvsDriver::Base] instance of driver. @param key [String] key of sorted_set.

# File lib/rails_kvs_driver/lists/list.rb, line 11
def initialize(driver_instance, key)
  @driver_instance = driver_instance
  @key = key
end

Public Instance Methods

[](index) click to toggle source

get value of the list. when the key or index doesn’t exist, return nil.

@param index [Integer] index of the list. @return [String] value

# File lib/rails_kvs_driver/lists/list.rb, line 21
def [](index)
  @driver_instance.get_list_value(@key, index)
end
[]=(index, value) click to toggle source

set value to index of the list. when the key or index doesn’t exist, raise error.

@param index [Integer] index of the list. @param value [String] value

# File lib/rails_kvs_driver/lists/list.rb, line 30
def []=(index, value)
  @driver_instance.set_list_value(@key, index, value)
end
delete(value) click to toggle source

delete value from list.

@param value [String] delete value.

# File lib/rails_kvs_driver/lists/list.rb, line 37
def delete(value)
  @driver_instance.delete_list_value(@key, value)
end
delete_at(index) click to toggle source

delete at index from list.

@param index [Integer] index of the list.

# File lib/rails_kvs_driver/lists/list.rb, line 44
def delete_at(index)
  @driver_instance.delete_list_value_at(@key, index)
end
each(limit=1000) { |position, value| ... } click to toggle source

execute the block of code for each value of the list.

@param limit [Integer] limit number to acquire at a time. (default=1000) @param &block [{|index, value| }] execute the block of code for each value of the list.

# File lib/rails_kvs_driver/lists/list.rb, line 52
def each(limit=1000)
  count    = length
  position = 0

  while position < count
    @driver_instance.get_list_values(@key, position, position + (limit-1)).each do |value|
      yield position, value
      position += 1
    end
  end
end
include?(value) click to toggle source

check if a value is included.

@param value [String] value @return [Boolean] result

# File lib/rails_kvs_driver/lists/list.rb, line 68
def include?(value)
  each do |index, list_value|
    return true if list_value == value
  end
  return false
end
length() click to toggle source

return length of the list.

# File lib/rails_kvs_driver/lists/list.rb, line 76
def length
  @driver_instance.count_list_value(@key)
end
Also aliased as: size
pop_first() click to toggle source

pop value from first of the list. when the key doesn’t exist or is empty. return nil.

@return [String] value of the key.

# File lib/rails_kvs_driver/lists/list.rb, line 100
def pop_first
  @driver_instance.pop_list_first(@key)
end
pop_last() click to toggle source

pop value from last of the list. when the key doesn’t exist or is empty. return nil.

@return [String] value of the key.

# File lib/rails_kvs_driver/lists/list.rb, line 108
def pop_last
  @driver_instance.pop_list_last(@key)
end
push_first(value) click to toggle source

push value to first of the list. when the key doesn’t exist, it’s made newly list.

@param value [String] value.

# File lib/rails_kvs_driver/lists/list.rb, line 84
def push_first(value)
  @driver_instance.push_list_first(@key, value)
end
push_last(value) click to toggle source

push value to last of the list. when the key doesn’t exist, it’s made newly list.

@param value [String] value.

# File lib/rails_kvs_driver/lists/list.rb, line 92
def push_last(value)
  @driver_instance.push_list_last(@key, value)
end
size()
Alias for: length