class RediSet::Quality

Attributes

attribute[R]
name[R]

Public Class Methods

collect_from_details(details) click to toggle source

parse a layered hash like “attribute_name => { quality_name => possessed? }” into a pair of Arrays of quality objects, one full of qualities they should possess, the other full of qualities they should not possess.

# File lib/redi_set/quality.rb, line 8
def self.collect_from_details(details)
  qheld = []
  qlacked = []
  details.each_pair do |attribute_name, attribute_details|
    attribute = Attribute.new(name: attribute_name)
    attribute_details.each_pair do |quality_name, is_held|
      quality = Quality.new(attribute: attribute, name: quality_name)
      if is_held
        qheld << quality
      else
        qlacked << quality
      end
    end
  end
  [qheld, qlacked]
end
new(attribute:, name:) click to toggle source
# File lib/redi_set/quality.rb, line 25
def initialize(attribute:, name:)
  @attribute = attribute
  @name = name
end

Public Instance Methods

key() click to toggle source
# File lib/redi_set/quality.rb, line 30
def key
  @_key ||= "#{RediSet.prefix}.attr:#{attribute.name}:#{name}"
end
set_all!(redis, ids) click to toggle source
# File lib/redi_set/quality.rb, line 34
def set_all!(redis, ids)
  redis.multi do
    redis.del(key)
    redis.sadd(key, ids)
  end
end