Sha256: 8eedd3f4e89828c2bd729fc7e2ac1e3f64617d1d35f992cbf230943a09212984

Contents?: true

Size: 532 Bytes

Versions: 44

Compression:

Stored size: 532 Bytes

Contents

module DbCharmer
  module Sharding
    module Method
      class HashMap
        attr_accessor :map

        def initialize(config)
          @map = config[:map].clone or raise ArgumentError, "No :map defined!"
        end

        def shard_for_key(key)
          res = map[key] || map[:default]
          raise ArgumentError, "Invalid key value, no shards found for this key!" unless res
          return res
        end

        def support_default_shard?
          map.has_key?(:default)
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
db-charmer-1.6.3 lib/db_charmer/sharding/method/hash_map.rb
db-charmer-1.6.2 lib/db_charmer/sharding/method/hash_map.rb
db-charmer-1.6.1 lib/db_charmer/sharding/method/hash_map.rb
db-charmer-1.6.0 lib/db_charmer/sharding/method/hash_map.rb