activerecord-shard_for 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a145bb643f713e31825e2bf87446c2657d10a1a4
|
4
|
+
data.tar.gz: 01eedb436a6b730078c624cf539fb5cd402c9495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c642c62650b872380169af15830b0c96c772f6aaf90bfa74340bb8e499eb794a90f5f905cc4fc74c8414189ee7faffa894a576baffac8085d26d01d56a4704e
|
7
|
+
data.tar.gz: 338d2512639fc8ababdad1d3b8f4afb4d1915026adc5d65622662be63237b6449b7d3cd4f546384461ef11c1bc3e881f7d8b1c879c10b3d024652930350fde3b
|
@@ -5,7 +5,7 @@ module ActiveRecord
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@cluster_configs = {}
|
8
|
-
@
|
8
|
+
@connection_routers = {}
|
9
9
|
end
|
10
10
|
|
11
11
|
# Define config for specific cluster.
|
@@ -37,7 +37,7 @@ module ActiveRecord
|
|
37
37
|
|
38
38
|
# @param [Symbol] router_name
|
39
39
|
# @return [Class] registered class by [#register_router]
|
40
|
-
def
|
40
|
+
def fetch_connection_router(router_name)
|
41
41
|
connection_routers[router_name]
|
42
42
|
end
|
43
43
|
end
|
@@ -6,7 +6,7 @@ module ActiveRecord
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
class_attribute :
|
9
|
+
class_attribute :connection_router, instance_writer: false
|
10
10
|
class_attribute :shard_repository, instance_writer: false
|
11
11
|
class_attribute :replication_mapping, instance_writer: false
|
12
12
|
class_attribute :distkey, instance_writer: false
|
@@ -17,8 +17,8 @@ module ActiveRecord
|
|
17
17
|
# @param [Symbol] name A cluster name which is set by ActiveRecord::ShardFor.configure
|
18
18
|
def use_cluster(name, router_name)
|
19
19
|
cluster_config = ActiveRecord::ShardFor.config.fetch_cluster_config(name)
|
20
|
-
|
21
|
-
self.
|
20
|
+
connection_router_class = ActiveRecord::ShardFor.config.fetch_connection_router(router_name)
|
21
|
+
self.connection_router = connection_router_class.new(cluster_config)
|
22
22
|
self.shard_repository = ActiveRecord::ShardFor::ShardRepogitory.new(cluster_config, self)
|
23
23
|
self.abstract_class = true
|
24
24
|
end
|
@@ -28,7 +28,7 @@ module ActiveRecord
|
|
28
28
|
# @param [String] key A value of distkey
|
29
29
|
# @return [Class] A generated model class for given distkey value
|
30
30
|
def shard_for(key)
|
31
|
-
connection_name =
|
31
|
+
connection_name = connection_router.fetch_connection_name(key)
|
32
32
|
shard_repository.fetch(connection_name)
|
33
33
|
end
|
34
34
|
|
@@ -5,7 +5,7 @@ require 'activerecord/shard_for/config'
|
|
5
5
|
require 'activerecord/shard_for/cluster_config'
|
6
6
|
require 'activerecord/shard_for/model'
|
7
7
|
require 'activerecord/shard_for/errors'
|
8
|
-
require 'activerecord/shard_for/
|
8
|
+
require 'activerecord/shard_for/connection_router'
|
9
9
|
require 'activerecord/shard_for/hash_modulo_router'
|
10
10
|
require 'activerecord/shard_for/database_tasks'
|
11
11
|
require 'activerecord/shard_for/shard_repogitory'
|