Sha256: 1a221dad6107ea7b9249ee80adc1c1f1cbacd9bba22438d0fba7cc16173bcb61

Contents?: true

Size: 670 Bytes

Versions: 3

Compression:

Stored size: 670 Bytes

Contents

class Kredis::Types::Set < Kredis::Types::Proxying
  proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop

  attr_accessor :typed

  def members
    strings_to_types(smembers || [], typed).sort
  end
  alias to_a members

  def add(*members)
    sadd types_to_strings(members) if members.flatten.any?
  end
  alias << add

  def remove(*members)
    srem types_to_strings(members) if members.flatten.any?
  end

  def replace(*members)
    multi do
      del
      add members
    end
  end

  def include?(member)
    sismember type_to_string(member)
  end

  def size
    scard.to_i
  end

  def take
    spop
  end

  def clear
    del
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kredis-0.3.0 lib/kredis/types/set.rb
kredis-0.2.3 lib/kredis/types/set.rb
kredis-0.2.2 lib/kredis/types/set.rb