Class: ActiveRecord::ShardFor::Config
- Inherits:
-
Object
- Object
- ActiveRecord::ShardFor::Config
- Defined in:
- lib/activerecord/shard_for/config.rb
Instance Attribute Summary collapse
-
#cluster_configs ⇒ Object
readonly
Returns the value of attribute cluster_configs.
-
#connection_routers ⇒ Object
readonly
Returns the value of attribute connection_routers.
Instance Method Summary collapse
-
#define_cluster(cluster_name) {|ActiveRecord::ShardFor::ClusterConfig| ... } ⇒ ActiveRecord::ShardFor::ClusterConfig
Define config for specific cluster.
- #fetch_cluster_config(cluster_name) ⇒ ActiveRecord::ShardFor::ClusterConfig
-
#fetch_connection_router(connection_router_name) ⇒ Class
Registered class by [#register_router].
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#register_connection_router(router_name, router_class) ⇒ Object
Register connection router for ActiveRecord::ShardFor See README.md for example.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
6 7 8 9 |
# File 'lib/activerecord/shard_for/config.rb', line 6 def initialize @cluster_configs = {} @connection_routers = {} end |
Instance Attribute Details
#cluster_configs ⇒ Object (readonly)
Returns the value of attribute cluster_configs.
4 5 6 |
# File 'lib/activerecord/shard_for/config.rb', line 4 def cluster_configs @cluster_configs end |
#connection_routers ⇒ Object (readonly)
Returns the value of attribute connection_routers.
4 5 6 |
# File 'lib/activerecord/shard_for/config.rb', line 4 def connection_routers @connection_routers end |
Instance Method Details
#define_cluster(cluster_name) {|ActiveRecord::ShardFor::ClusterConfig| ... } ⇒ ActiveRecord::ShardFor::ClusterConfig
Define config for specific cluster. See README.md for example. raise [RuntimeError] when this cluster config is invalid.
17 18 19 20 21 |
# 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) ⇒ ActiveRecord::ShardFor::ClusterConfig
26 27 28 |
# 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) ⇒ Class
Returns registered class by [#register_router].
41 42 43 |
# 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) ⇒ Object
Register connection router for ActiveRecord::ShardFor See README.md for example.
34 35 36 |
# File 'lib/activerecord/shard_for/config.rb', line 34 def register_connection_router(router_name, router_class) connection_routers[router_name] = router_class end |