class Relix::UniqueIndex
Public Instance Methods
all(r, options={})
click to toggle source
# File lib/relix/indexes/unique.rb, line 51 def all(r, options={}) r.zrange(sorted_set_name, *range_from_options(r, options)) end
deindex(r, pk, old_value)
click to toggle source
# File lib/relix/indexes/unique.rb, line 41 def deindex(r, pk, old_value) r.hdel(hash_name, old_value) r.zrem(sorted_set_name, pk) end
destroy_all(r)
click to toggle source
# File lib/relix/indexes/unique.rb, line 46 def destroy_all(r) r.del(hash_name) r.del(sorted_set_name) end
eq(r, value, options={})
click to toggle source
# File lib/relix/indexes/unique.rb, line 55 def eq(r, value, options={}) [r.hget(hash_name, value)].compact end
filter(r, pk, object, value)
click to toggle source
Calls superclass method
Relix::Index#filter
# File lib/relix/indexes/unique.rb, line 17 def filter(r, pk, object, value) v = r.hget(hash_name, value) if(v && (v != pk)) raise NotUniqueError.new("'#{value}' is not unique in index #{name}") end super end
hash_name()
click to toggle source
# File lib/relix/indexes/unique.rb, line 9 def hash_name @set.keyer.component(name, 'lookup') end
index(r, pk, object, value, old_value)
click to toggle source
# File lib/relix/indexes/unique.rb, line 30 def index(r, pk, object, value, old_value) if read(object).values.all?{|e| !e.nil?} r.hset(hash_name, value, pk) r.zadd(sorted_set_name, score(object, value), pk) else r.hdel(hash_name, value) r.zrem(sorted_set_name, pk) end r.hdel(hash_name, old_value) end
index?(r, object, value)
click to toggle source
Calls superclass method
Relix::Index#index?
# File lib/relix/indexes/unique.rb, line 25 def index?(r, object, value) return false if read(object).values.any?{|e| e.nil?} super end
sorted_set_name()
click to toggle source
# File lib/relix/indexes/unique.rb, line 5 def sorted_set_name @set.keyer.component(name, 'ordering') end
watch_keys(*values)
click to toggle source
# File lib/relix/indexes/unique.rb, line 13 def watch_keys(*values) hash_name end