Sha256: 3859d9b72ecc815e4d13ae755a1747aa7829bdcaf5ef9444625d5e5ce9c8fa81
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
module ActiveRecord module ShardFor class Config attr_reader :cluster_configs, :routers def initialize @cluster_configs = {} @routers = {} end # 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. def define_cluster(cluster_name, &block) cluster_config = ClusterConfig.new(cluster_name) cluster_config.instance_eval(&block) cluster_configs[cluster_name] = cluster_config end # @param [Symbol] cluster_name # @return [ActiveRecord::ShardFor::ClusterConfig] # @raise [KeyError] when not registered key given def fetch_cluster_config(cluster_name) cluster_configs.fetch(cluster_name) end # Register router for ActiveRecord::ShardFor # See README.md for example. # @param [Symbol] router_name # @router_class [Class] router_class def register_cluster_router(router_name, router_class) routers[router_name] = router_class end # @param [Symbol] router_name # @return [Class] registered class by [#register_router] def fetch_cluster_router(router_name) routers[router_name] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-shard_for-0.1.0 | lib/activerecord/shard_for/config.rb |