class ActiveRecord::ShardFor::Config
Attributes
cluster_configs[R]
connection_routers[R]
Public Class Methods
new()
click to toggle source
# File lib/activerecord/shard_for/config.rb, line 6 def initialize @cluster_configs = {} @connection_routers = {} end
Public Instance Methods
define_cluster(cluster_name, &block)
click to toggle source
Define config for specific cluster. See README.md for example. @param [String] cluster_name @yield [ActiveRecord::ShardFor::ClusterConfig] @return [ActiveRecord::ShardFor::ClusterConfig] raise [RuntimeError] when this cluster config is invalid.
# File lib/activerecord/shard_for/config.rb, line 17 def define_cluster(cluster_name, &block) cluster_config = ClusterConfig.new(cluster_name) cluster_config.instance_eval(&block) cluster_configs[cluster_name] = cluster_config end
fetch_cluster_config(cluster_name)
click to toggle source
@param [Symbol] cluster_name @return [ActiveRecord::ShardFor::ClusterConfig] @raise [KeyError] when not registered key given
# File lib/activerecord/shard_for/config.rb, line 26 def fetch_cluster_config(cluster_name) cluster_configs.fetch(cluster_name) end
fetch_connection_router(connection_router_name)
click to toggle source
@param [Symbol] connection_router_name @return [Class] registered class by [#register_router] @raise [KeyError] when not registerd router_name given
# File lib/activerecord/shard_for/config.rb, line 41 def fetch_connection_router(connection_router_name) connection_routers.fetch(connection_router_name) end
register_connection_router(router_name, router_class)
click to toggle source
Register connection router for ActiveRecord::ShardFor
See README.md for example. @param [Symbol] router_name @router_class [Class] router_class
# File lib/activerecord/shard_for/config.rb, line 34 def register_connection_router(router_name, router_class) connection_routers[router_name] = router_class end