db-charmer 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 1.6.3 (2010-04-03):
2
+
3
+ Bugfix release: Modified stub connection initialization code to set default connections
4
+ for sharded models using shards enumeration or default shard features of sharding methods.
5
+
6
+ ----------------------------------------------------------------------------------------
1
7
  1.6.2 (2010-04-03):
2
8
 
3
9
  Bugfix release: Modified our stub connection used on sharded models to fail on db-calling
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.2
1
+ 1.6.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{db-charmer}
8
- s.version = "1.6.2"
8
+ s.version = "1.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexey Kovyrin"]
@@ -23,7 +23,20 @@ module DbCharmer
23
23
  if opt[:sharded]
24
24
  raise ArgumentError, "Can't use sharding on a model with slaves!" if opt[:slaves].any?
25
25
  setup_sharding_magic(opt[:sharded])
26
- setup_connection_magic(DbCharmer::StubConnection.new)
26
+
27
+ # If method supports shards enumeration, get the first shard
28
+ conns = sharded_connection.shard_connections || []
29
+ real_conn = conns.first
30
+
31
+ # If connection we do not have real connection yet, try to use the default one
32
+ real_conn ||= sharded_connection.sharder.shard_for_key(:default) if sharded_connection.support_default_shard?
33
+
34
+ # Create stub connection
35
+ real_conn = coerce_to_connection_proxy(real_conn, DbCharmer.connections_should_exist?) if real_conn
36
+ stub_conn = DbCharmer::StubConnection.new(real_conn)
37
+
38
+ # ... and set it as the default one for this model
39
+ setup_connection_magic(stub_conn)
27
40
  end
28
41
  end
29
42
 
@@ -6,6 +6,10 @@
6
6
  #
7
7
  module DbCharmer
8
8
  class StubConnection
9
+ def initialize(real_conn = nil)
10
+ @real_conn = real_conn
11
+ end
12
+
9
13
  def set_real_connection(real_conn)
10
14
  @real_conn = real_conn
11
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 6
8
- - 2
9
- version: 1.6.2
8
+ - 3
9
+ version: 1.6.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexey Kovyrin