Class: Redisabel::KeySet
Instance Attribute Summary
Attributes inherited from KeyValue
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from KeyValue
#autosave=, #autosave?, database_key_name, #destroy, #empty?, #eql?, #initialize, #inspect, #load, #to_s, #value
detect_type, transform, transform_hash, transform_list, transform_set, transform_string, transform_zset
Methods included from Finders
#filter, #find
Class Method Details
.data_type ⇒ Object
4
5
6
|
# File 'lib/redisabel/key_set.rb', line 4
def self.data_type
return Array
end
|
Instance Method Details
#==(other) ⇒ Object
41
42
43
44
|
# File 'lib/redisabel/key_set.rb', line 41
def ==(other)
return (other.is_a?(KeyValue) && self.id == other.id &&
@data.sort == other.value.sort)
end
|
#delete(value) ⇒ Object
21
22
23
24
25
|
# File 'lib/redisabel/key_set.rb', line 21
def delete(value)
if @data.delete(value) && self.autosave? && !self.id.to_s.empty?
Database.db.srem(self.database_key, value)
end
end
|
#push(*values) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/redisabel/key_set.rb', line 27
def push(*values)
values = values.shift if values.first.is_a?(Array)
values.uniq!
@data += values - @data
if self.autosave? && !self.id.to_s.empty?
values.each{ |v| Database.db.sadd(self.database_key, v) }
end
end
|
#save ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/redisabel/key_set.rb', line 13
def save
return super do |key|
Database.db.del(key)
results = @data.map{ |v| Database.db.sadd(key, v) }
next results.all?
end
end
|
#to_ary ⇒ Object
Also known as:
to_a
36
37
38
|
# File 'lib/redisabel/key_set.rb', line 36
def to_ary
return @data.dup
end
|
#value=(val) ⇒ Object
46
47
48
49
|
# File 'lib/redisabel/key_set.rb', line 46
def value=(val)
super
@data.uniq!
end
|