Class: Canery::Tub
- Inherits:
-
Object
- Object
- Canery::Tub
- Defined in:
- lib/canery/tub.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object (also: #[])
- #has_key?(key) ⇒ Boolean (also: #key?)
-
#initialize(backend, name) ⇒ Tub
constructor
A new instance of Tub.
- #keys ⇒ Object
- #length ⇒ Object (also: #size, #count)
- #mget(keys) ⇒ Object
- #mset(data) ⇒ Object
- #rename(old_key, new_key) ⇒ Object
- #set(key, value) ⇒ Object (also: #[]=)
- #sort(order, limit = nil) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(backend, name) ⇒ Tub
Returns a new instance of Tub.
10 11 12 13 14 |
# File 'lib/canery/tub.rb', line 10 def initialize(backend, name) raise ArgumentError, "unknown backend type" unless Canery::Backend === backend raise ArgumentError, "name of tub must be a String" unless String === name @backend, @name = backend, name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/canery/tub.rb', line 8 def name @name end |
Instance Method Details
#clear ⇒ Object
38 39 40 |
# File 'lib/canery/tub.rb', line 38 def clear backend.call(:clear, name) end |
#delete(key) ⇒ Object
34 35 36 |
# File 'lib/canery/tub.rb', line 34 def delete(key) backend.call(:delete, name, key) end |
#get(key) ⇒ Object Also known as: []
16 17 18 |
# File 'lib/canery/tub.rb', line 16 def get(key) backend.call(:get, name, key) end |
#has_key?(key) ⇒ Boolean Also known as: key?
42 43 44 |
# File 'lib/canery/tub.rb', line 42 def has_key?(key) backend.call(:has_key?, name, key) end |
#keys ⇒ Object
47 48 49 |
# File 'lib/canery/tub.rb', line 47 def keys backend.call(:keys, name) end |
#length ⇒ Object Also known as: size, count
67 68 69 |
# File 'lib/canery/tub.rb', line 67 def length backend.call(:count, name) end |
#mget(keys) ⇒ Object
21 22 23 |
# File 'lib/canery/tub.rb', line 21 def mget(keys) backend.call(:mget, name, keys) end |
#mset(data) ⇒ Object
30 31 32 |
# File 'lib/canery/tub.rb', line 30 def mset(data) backend.call(:mset, name, data) end |
#rename(old_key, new_key) ⇒ Object
63 64 65 |
# File 'lib/canery/tub.rb', line 63 def rename(old_key, new_key) backend.call(:rename, name, old_key, new_key) end |
#set(key, value) ⇒ Object Also known as: []=
25 26 27 |
# File 'lib/canery/tub.rb', line 25 def set(key, value) backend.call(:set, name, key || uuid, value) end |
#sort(order, limit = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/canery/tub.rb', line 55 def sort(order, limit = nil) begin backend.call(:sort, name, order, limit) rescue ArgumentError => e raise Canery::CaneryError, e end end |
#values ⇒ Object
51 52 53 |
# File 'lib/canery/tub.rb', line 51 def values backend.call(:values, name) end |