lib/redis/objects/hashes.rb in redis-objects-0.4.0 vs lib/redis/objects/hashes.rb in redis-objects-0.4.1
- old
+ new
@@ -13,24 +13,25 @@
module ClassMethods
# Define a new hash key. It will function like a regular instance
# method, so it can be used alongside ActiveRecord, DataMapper, etc.
def hash_key(name, options={})
@redis_objects[name.to_sym] = options.merge(:type => :dict)
+ klass_name = '::' + self.name
if options[:global]
instance_eval <<-EndMethods
def #{name}
- @#{name} ||= Redis::Hash.new(field_key(:#{name}), redis, @redis_objects[:#{name}])
+ @#{name} ||= Redis::Hash.new(redis_field_key(:#{name}), #{klass_name}.redis, #{klass_name}.redis_objects[:#{name}])
end
EndMethods
class_eval <<-EndMethods
def #{name}
self.class.#{name}
end
EndMethods
else
class_eval <<-EndMethods
def #{name}
- @#{name} ||= Redis::Hash.new(field_key(:#{name}), redis, self.class.redis_objects[:#{name}])
+ @#{name} ||= Redis::Hash.new(redis_field_key(:#{name}), #{klass_name}.redis, #{klass_name}.redis_objects[:#{name}])
end
EndMethods
end
end
end