Class: RediSet::Quality
- Inherits:
-
Object
- Object
- RediSet::Quality
- Defined in:
- lib/redi_set/quality.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.collect_from_details(details) ⇒ Object
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.
Instance Method Summary collapse
-
#initialize(attribute:, name:) ⇒ Quality
constructor
A new instance of Quality.
- #key ⇒ Object
- #set_all!(redis, ids) ⇒ Object
Constructor Details
#initialize(attribute:, name:) ⇒ Quality
Returns a new instance of Quality.
25 26 27 28 |
# File 'lib/redi_set/quality.rb', line 25 def initialize(attribute:, name:) @attribute = attribute @name = name end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/redi_set/quality.rb', line 3 def attribute @attribute end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/redi_set/quality.rb', line 3 def name @name end |
Class Method Details
.collect_from_details(details) ⇒ Object
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.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#key ⇒ Object
30 31 32 |
# File 'lib/redi_set/quality.rb', line 30 def key @_key ||= "#{RediSet.prefix}.attr:#{attribute.name}:#{name}" end |
#set_all!(redis, ids) ⇒ Object
34 35 36 37 38 39 |
# 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 |