Module: Redis::Objects::ClassMethods
- Defined in:
- lib/redis/objects.rb
Overview
Class methods that appear in your class when you include Redis::Objects.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #first_ancestor_with(name) ⇒ Object
-
#redis_field_key(name, id = nil, context = self) ⇒ Object
:nodoc:.
-
#redis_field_redis(name) ⇒ Object
:nodoc:.
- #redis_id_field(id = nil) ⇒ Object
-
#redis_prefix(klass = self) ⇒ Object
:nodoc:.
-
#redis_prefix=(redis_prefix) ⇒ Object
Set the Redis redis_prefix to use.
Instance Attribute Details
#redis ⇒ Object
92 93 94 |
# File 'lib/redis/objects.rb', line 92 def redis @redis || Objects.redis end |
#redis_objects ⇒ Object
98 99 100 |
# File 'lib/redis/objects.rb', line 98 def redis_objects @redis_objects ||= {} end |
Instance Method Details
#first_ancestor_with(name) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/redis/objects.rb', line 137 def first_ancestor_with(name) if redis_objects && redis_objects.key?(name.to_sym) self elsif superclass && superclass.respond_to?(:redis_objects) superclass.first_ancestor_with(name) end end |
#redis_field_key(name, id = nil, context = self) ⇒ Object
:nodoc:
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/redis/objects.rb', line 117 def redis_field_key(name, id=nil, context=self) #:nodoc: klass = first_ancestor_with(name) # READ THIS: This can never ever ever ever change or upgrades will corrupt all data # I don't think people were using Proc as keys before (that would create a weird key). Should be ok if key = klass.redis_objects[name.to_sym][:key] if key.respond_to?(:call) key = key.call context else context.instance_eval "%(#{key})" end else if id.nil? and !klass.redis_objects[name.to_sym][:global] raise NilObjectId, "[#{klass.redis_objects[name.to_sym]}] Attempt to address redis-object " + ":#{name} on class #{klass.name} with nil id (unsaved record?) [object_id=#{object_id}]" end "#{redis_prefix(klass)}:#{id}:#{name}" end end |
#redis_field_redis(name) ⇒ Object
:nodoc:
112 113 114 115 |
# File 'lib/redis/objects.rb', line 112 def redis_field_redis(name) #:nodoc: klass = first_ancestor_with(name) return klass.redis_objects[name.to_sym][:redis] || self.redis end |
#redis_id_field(id = nil) ⇒ Object
145 146 147 |
# File 'lib/redis/objects.rb', line 145 def redis_id_field(id=nil) @redis_id_field = id || @redis_id_field || :id end |
#redis_prefix(klass = self) ⇒ Object
:nodoc:
104 105 106 107 108 109 110 |
# File 'lib/redis/objects.rb', line 104 def redis_prefix(klass = self) #:nodoc: @redis_prefix ||= klass.name.to_s. sub(%r{(.*::)}, ''). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase end |
#redis_prefix=(redis_prefix) ⇒ Object
Set the Redis redis_prefix to use. Defaults to model_name
103 |
# File 'lib/redis/objects.rb', line 103 def redis_prefix=(redis_prefix) @redis_prefix = redis_prefix end |