yankov
11/8/2011 - 10:18 PM

gistfile1.rb


 def where *params
   shard_key = params.find{|x| x.has_key?(:player_id)}
   params.first.merge!(:shard_id => Digest::MD5.hexdigest(shard_key[:player_id])) unless shard_key.nil?
   super *params
 end

# checking in console
ruby-1.9.2-p290 :079 > Activity.where(:player_id => "4e5d4e27b262e3fbe0000050").selector
 => {:deleted_at=>{"$exists"=>false}, :player_id=>BSON::ObjectId('4e5d4e27b262e3fbe0000050'), :shard_id=>"0ce2aee649f332e56751b41bc9e2844e"}