Created
June 2, 2011 05:02
-
-
Save tribalvibes/1003960 to your computer and use it in GitHub Desktop.
Implement SUNIONSTORE volatile find keys for Ohm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def keys(hash) | |
model.debug("#{model.name}.find: #{key} : #{hash}") | |
[].tap do |keys| | |
hash.each do |attr, values| | |
# nb: String is Enumerable in 1.8.x... | |
attr_type = model.types[attr] | |
if !(Enumerable === values) || ( attr_type && attr_type < Enumerable && attr_type != String ) | |
Array(values).each do |v| | |
keys << model.index_key_for(attr, v) | |
end | |
else | |
keys << union_key_for(attr,values) | |
end | |
end | |
end.uniq | |
end | |
def union_key_for(attr, values) | |
model.debug "union_key_for: #{attr}: #{values}" | |
source = values.map {|v| model.index_key_for(attr, v) } | |
target = source.reduce(&:*) | |
apply(:sunionstore, source.shift, source, target) | |
target | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment