Sha256: 45ff8255bb564d422991d8b98e384f14004366ceac8d0d638068c100a100a87a

Contents?: true

Size: 822 Bytes

Versions: 6

Compression:

Stored size: 822 Bytes

Contents

require File.dirname(__FILE__) + '/base_object'

class Redis
  #
  # Class representing a Redis enumerable type (list, set, sorted set, or hash).
  #
  class EnumerableObject < BaseObject
    include Enumerable

    # Iterate through each member. Redis::Objects mixes in Enumerable,
    # so you can also use familiar methods like +collect+, +detect+, and so forth.
    def each(&block)
      value.each(&block)
    end

    def sort(options={})
      return super() if block_given?
      options[:order] = "asc alpha" if options.keys.count == 0  # compat with Ruby
      val = redis.sort(key, **options)
      val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val
    end

    # ActiveSupport's core extension `Enumerable#as_json` implementation is incompatible with ours.
    def as_json(*)
      to_hash
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
redis-objects-2.0.0.beta lib/redis/enumerable_object.rb
redis-objects-2.0.0.alpha lib/redis/enumerable_object.rb
redis-objects-1.7.0 lib/redis/enumerable_object.rb
redis-objects-1.6.0 lib/redis/enumerable_object.rb
redis-objects-legacy-1.6.0 lib/redis/enumerable_object.rb
redis-objects-1.5.1 lib/redis/enumerable_object.rb