Module: Redis::Objects::SortedSets::ClassMethods

Defined in:
lib/redis/objects/sorted_sets.rb

Overview

Class methods that appear in your class when you include Redis::Objects.

Instance Method Summary collapse

Instance Method Details

#sorted_set(name, options = {}) ⇒ Object

Define a new list. It will function like a regular instance method, so it can be used alongside ActiveRecord, DataMapper, etc.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redis/objects/sorted_sets.rb', line 16

def sorted_set(name, options={})
  @redis_objects[name.to_sym] = options.merge(:type => :sorted_set)
  if options[:global]
    instance_eval <<-EndMethods
      def #{name}
        @#{name} ||= Redis::SortedSet.new(field_key(:#{name}), redis, @redis_objects[:#{name}])
      end
    EndMethods
    class_eval <<-EndMethods
      def #{name}
        self.class.#{name}
      end
    EndMethods
  else
    class_eval <<-EndMethods
      def #{name}
        @#{name} ||= Redis::SortedSet.new(field_key(:#{name}), redis, self.class.redis_objects[:#{name}])
      end
    EndMethods
  end
end