Sha256: 108d007d5bdeaf33da2f3352c97f3d554cc3ac47738232a2378c987d5957f065

Contents?: true

Size: 710 Bytes

Versions: 3

Compression:

Stored size: 710 Bytes

Contents

module Blendris

  # RedisList is a wrapper for the Redis LIST data type.

  class RedisList

    include RedisNode
    include Enumerable

    def initialize(key, options = {})
      @key = key.to_s
      @options = options
      @on_change = options[:on_change]
    end

    def each
      redis.lrange(key, 0, -1).each do |value|
        yield value
      end
    end

    def <<(value)
      values = [ value ].flatten.compact

      values.flatten.compact.each do |v|
        redis.rpush key, v
      end

      notify_changed if values.count > 0

      self
    end

    def get
      self
    end

    def delete(value)
      redis.lrem key, 0, value
    ensure
      notify_changed
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blendris-0.5 lib/blendris/list.rb
blendris-0.0.4 lib/blendris/list.rb
blendris-0.0.3 lib/blendris/list.rb