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

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



77
78
79
# File 'lib/redis/objects.rb', line 77

def redis
  @redis
end

#redis_objectsObject

Returns the value of attribute redis_objects.



77
78
79
# File 'lib/redis/objects.rb', line 77

def redis_objects
  @redis_objects
end

Instance Method Details

#first_ancestor_with(name) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/redis/objects.rb', line 95

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 = '') ⇒ Object

:nodoc:



89
90
91
92
93
# File 'lib/redis/objects.rb', line 89

def redis_field_key(name, id='') #:nodoc:
  klass = first_ancestor_with(name)
  # This can never ever ever ever change or upgrades will corrupt all data
  klass.redis_objects[name.to_sym][:key] || "#{redis_prefix(klass)}:#{id}:#{name}"
end

#redis_prefix(klass = self) ⇒ Object

:nodoc:



81
82
83
84
85
86
87
# File 'lib/redis/objects.rb', line 81

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



80
# File 'lib/redis/objects.rb', line 80

def redis_prefix=(redis_prefix) @redis_prefix = redis_prefix end