class ActiveRecord::ShardFor::ConnectionRouter
@abstract Subclass and override [#route] to inplement
Attributes
cluster_config[R]
Public Class Methods
new(cluster_config)
click to toggle source
@param [ActiveRecord::ShardFor::ClusterConfig]
# File lib/activerecord/shard_for/connection_router.rb, line 8 def initialize(cluster_config) @cluster_config = cluster_config end
Public Instance Methods
fetch_connection_name(key)
click to toggle source
Fetch shard by sharding key @param [Object] key routing key
# File lib/activerecord/shard_for/connection_router.rb, line 14 def fetch_connection_name(key) cluster_config.fetch route(key) end
route(_key)
click to toggle source
Decide routing for shard. Override this method in subclass. @param [Object] key sharding key
# File lib/activerecord/shard_for/connection_router.rb, line 21 def route(_key) raise NotImplementedError.new, 'Please impement this method' end
Private Instance Methods
connection_count()
click to toggle source
@return [Integer] count of registered connection
# File lib/activerecord/shard_for/connection_router.rb, line 28 def connection_count cluster_config.connections.count end