Class: Redis::Attrs::Complex
Instance Attribute Summary
Attributes inherited from Base
#klass, #name, #options, #type
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass, name, type, options) ⇒ Complex
constructor
A new instance of Complex.
Methods inherited from Base
Constructor Details
#initialize(klass, name, type, options) ⇒ Complex
Returns a new instance of Complex.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/redis-attrs/complex.rb', line 13 def initialize(klass, name, type, ) super attr = self attr_class = self.class.redis_object_class[type] # Define the getter klass.send(:define_method, name) do instance_variable_get("@#{name}") || begin obj = attr_class.new attr.redis_key(id), redis, instance_variable_set("@#{name}", obj) end end # TODO: Add support for collection setters if self.respond_to?(:setter) klass.send(:define_method, "#{name}=") do |value| obj = send(name) attr.setter(id, obj, value) end end end |
Class Method Details
.redis_object_class ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/redis-attrs/complex.rb', line 35 def self.redis_object_class @@redis_object_class ||= { lock: Redis::Lock, counter: Redis::Counter, hash: Redis::HashKey, list: Redis::Attrs::FilteredList, set: Redis::Attrs::FilteredSet, sorted_set: Redis::SortedSet, } end |