class DbCharmer::Sharding::Method::HashMap

Attributes

map[RW]

Public Class Methods

new(config) click to toggle source
# File lib/db_charmer/sharding/method/hash_map.rb, line 7
def initialize(config)
  @map = config[:map].clone or raise ArgumentError, "No :map defined!"
end

Public Instance Methods

shard_for_key(key) click to toggle source
# File lib/db_charmer/sharding/method/hash_map.rb, line 11
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
support_default_shard?() click to toggle source
# File lib/db_charmer/sharding/method/hash_map.rb, line 17
def support_default_shard?
  map.has_key?(:default)
end