Class: Kredis::Types::List

Inherits:
Proxying show all
Includes:
DefaultValues
Defined in:
lib/kredis/types/list.rb

Direct Known Subclasses

UniqueList

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy

Instance Method Summary collapse

Methods included from DefaultValues

#initialize

Methods inherited from Proxying

#failsafe, #initialize, proxying, #unproxied_redis

Instance Attribute Details

#typedObject

Returns the value of attribute typed.



8
9
10
# File 'lib/kredis/types/list.rb', line 8

def typed
  @typed
end

Instance Method Details

#append(*elements) ⇒ Object Also known as: <<



23
24
25
# File 'lib/kredis/types/list.rb', line 23

def append(*elements)
  rpush types_to_strings(elements, typed) if elements.flatten.any?
end

#clearObject



28
29
30
# File 'lib/kredis/types/list.rb', line 28

def clear
  del
end

#elementsObject Also known as: to_a



10
11
12
# File 'lib/kredis/types/list.rb', line 10

def elements
  strings_to_types(lrange(0, -1) || [], typed)
end

#last(n = nil) ⇒ Object



32
33
34
# File 'lib/kredis/types/list.rb', line 32

def last(n = nil)
  n ? lrange(-n, -1) : lrange(-1, -1).first
end

#prepend(*elements) ⇒ Object



19
20
21
# File 'lib/kredis/types/list.rb', line 19

def prepend(*elements)
  lpush types_to_strings(elements, typed) if elements.flatten.any?
end

#remove(*elements) ⇒ Object



15
16
17
# File 'lib/kredis/types/list.rb', line 15

def remove(*elements)
  types_to_strings(elements, typed).each { |element| lrem 0, element }
end