Sha256: 49f4b4a0f6af4544dbd956039ccf4e95111001b23a1bc238cc8cb69d17561064

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# This is the class loader, for use as "include Redis::Objects::Sets"
# For the object itself, see "Redis::Set"
require 'redis/set'
class Redis
  module Objects
    module Sets
      def self.included(klass)
        klass.send :include, InstanceMethods
        klass.extend ClassMethods
      end

      # Class methods that appear in your class when you include Redis::Objects.
      module ClassMethods
        # 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={})
          @redis_objects[name.to_sym] = 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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis-objects-0.4.0 lib/redis/objects/sets.rb
redis-objects-0.3.2 lib/redis/objects/sets.rb
redis-objects-0.3.1 lib/redis/objects/sets.rb