Class: Redistry::List::CollectionProxy
- Inherits:
-
Object
- Object
- Redistry::List::CollectionProxy
- Defined in:
- lib/redistry/list/collection_proxy.rb
Instance Attribute Summary (collapse)
-
- (Object) collection_name
Returns the value of attribute collection_name.
-
- (Object) klass
Returns the value of attribute klass.
-
- (Object) options
Returns the value of attribute options.
Instance Method Summary (collapse)
- - (Object) add(*objs)
- - (Object) all
- - (Object) clear
-
- (CollectionProxy) initialize(klass, collection_name, options = {})
constructor
A new instance of CollectionProxy.
- - (Object) key
Constructor Details
- (CollectionProxy) initialize(klass, collection_name, options = {})
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
- (Object) collection_name
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 |
- (Object) klass
Returns the value of attribute klass
4 5 6 |
# File 'lib/redistry/list/collection_proxy.rb', line 4 def klass @klass end |
- (Object) options
Returns the value of attribute options
4 5 6 |
# File 'lib/redistry/list/collection_proxy.rb', line 4 def @options end |
Instance Method Details
- (Object) add(*objs)
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 |
- (Object) all
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 |
- (Object) clear
30 31 32 33 |
# File 'lib/redistry/list/collection_proxy.rb', line 30 def clear Redistry.client.del(key) self end |
- (Object) key
35 36 37 |
# File 'lib/redistry/list/collection_proxy.rb', line 35 def key @key ||= "#{klass.name}-#{collection_name.to_s}" end |