Sha256: 5e6b74888b0a06aa07c9e90c20bf042bb238f8dd3b5b84b952f7b0db1078d813
Contents?: true
Size: 742 Bytes
Versions: 15
Compression:
Stored size: 742 Bytes
Contents
module DbCharmer module Sharding module Method class Range attr_accessor :ranges def initialize(config) @ranges = config[:ranges] ? config[:ranges].clone : raise(ArgumentError, "No :ranges defined!") end def shard_for_key(key) return ranges[:default] if key == :default ranges.each do |range, shard| next if range == :default return shard if range.member?(key.to_i) end return ranges[:default] if ranges[:default] raise ArgumentError, "Invalid key value, no shards found for this key!" end def support_default_shard? ranges.has_key?(:default) end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems