Skip to content

Instantly share code, notes, and snippets.

@tribalvibes
Created June 2, 2011 05:02
Show Gist options
  • Save tribalvibes/1003960 to your computer and use it in GitHub Desktop.
Save tribalvibes/1003960 to your computer and use it in GitHub Desktop.
Implement SUNIONSTORE volatile find keys for Ohm
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