lib/redis/objects/sets.rb in redis-objects-0.2.1 vs lib/redis/objects/sets.rb in redis-objects-0.2.2
- old
+ new
@@ -3,27 +3,38 @@
require 'redis/set'
class Redis
module Objects
module Sets
def self.included(klass)
- klass.instance_variable_set('@sets', {})
klass.send :include, InstanceMethods
klass.extend ClassMethods
end
# Class methods that appear in your class when you include Redis::Objects.
module ClassMethods
- attr_reader :sets
-
# Define a new list. It will function like a regular instance
# method, so it can be used alongside ActiveRecord, DataMapper, etc.
def set(name, options={})
- @sets[name] = options
- class_eval <<-EndMethods
- def #{name}
- @#{name} ||= Redis::Set.new(field_key(:#{name}), redis, self.class.sets[:#{name}])
- end
- EndMethods
+ @redis_objects[name] = options.merge(:type => :set)
+ if options[:global]
+ instance_eval <<-EndMethods
+ def #{name}
+ @#{name} ||= Redis::Set.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::Set.new(field_key(:#{name}), redis, self.class.redis_objects[:#{name}])
+ end
+ EndMethods
+ end
+
end
end
# Instance methods that appear in your class when you include Redis::Objects.
module InstanceMethods
\ No newline at end of file