Class: Redistry::List::CollectionProxy
- Inherits:
-
Object
- Object
- Redistry::List::CollectionProxy
- Defined in:
- lib/redistry/list/collection_proxy.rb
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
Returns the value of attribute collection_name.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add(*objs) ⇒ Object
- #all ⇒ Object
- #clear ⇒ Object
-
#initialize(klass, collection_name, options = {}) ⇒ CollectionProxy
constructor
A new instance of CollectionProxy.
- #key ⇒ Object
Constructor Details
#initialize(klass, collection_name, options = {}) ⇒ CollectionProxy
Returns a new instance of CollectionProxy.
6 7 8 9 10 11 |
# File 'lib/redistry/list/collection_proxy.rb', line 6 def initialize(klass, collection_name, = {}) self.klass = klass self.collection_name = collection_name self. = .merge() setup_serializer! end |
Instance Attribute Details
#collection_name ⇒ Object
Returns the value of attribute collection_name.
4 5 6 |
# File 'lib/redistry/list/collection_proxy.rb', line 4 def collection_name @collection_name end |
#klass ⇒ Object
Returns the value of attribute klass.
4 5 6 |
# File 'lib/redistry/list/collection_proxy.rb', line 4 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/redistry/list/collection_proxy.rb', line 4 def @options end |
Instance Method Details
#add(*objs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/redistry/list/collection_proxy.rb', line 18 def add(*objs) serialized_objs = @serializer.serialize(klass, objs.flatten) serialized_objs.reverse.each do |val| Redistry.client.lpush(key, val) end if [:size] Redistry.client.ltrim(key,0,[:size]-1) end self end |
#all ⇒ Object
13 14 15 16 |
# File 'lib/redistry/list/collection_proxy.rb', line 13 def all serialized_objs = Redistry.client.lrange(key,0,-1) serialized_objs.nil? || serialized_objs.empty? ? [] : @serializer.deserialize(klass, serialized_objs) end |
#clear ⇒ Object
30 31 32 33 |
# File 'lib/redistry/list/collection_proxy.rb', line 30 def clear Redistry.client.del(key) self end |
#key ⇒ Object
35 36 37 |
# File 'lib/redistry/list/collection_proxy.rb', line 35 def key @key ||= "#{klass.name}-#{collection_name.to_s}" end |