Sha256: 66f235abd9acf965a78f27963baea8f23e2ea36ebcf8a2652b50de4ba2c57d79

Contents?: true

Size: 312 Bytes

Versions: 6

Compression:

Stored size: 312 Bytes

Contents

# -*- coding: utf-8 -*-
module ActiveRecord::Turntable::Algorithm
  class ModuloAlgorithm < Base
    def choose(shard_maps, key)
      shard_maps[key % shard_maps.size].shard
    rescue
      raise ActiveRecord::Turntable::CannotSpecifyShardError, "cannot specify shard for key:#{key.inspect}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.1 lib/active_record/turntable/algorithm/modulo_algorithm.rb
activerecord-turntable-4.4.0 lib/active_record/turntable/algorithm/modulo_algorithm.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/algorithm/modulo_algorithm.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/algorithm/modulo_algorithm.rb
activerecord-turntable-4.1.0 lib/active_record/turntable/algorithm/modulo_algorithm.rb
activerecord-turntable-4.0.0 lib/active_record/turntable/algorithm/modulo_algorithm.rb