dynashard 0.4.0 → 0.4.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynashard}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nick Hengeveld"]
12
- s.date = %q{2011-02-14}
12
+ s.date = %q{2011-02-17}
13
13
  s.description = %q{Dynashard allows you to shard your ActiveRecord models. Models can be configured to shard based on context that can be defined dynamically.}
14
14
  s.email = %q{nickh@verticalresponse.com}
15
15
  s.extra_rdoc_files = [
@@ -3,7 +3,7 @@ module Dynashard
3
3
  def self.included(base)
4
4
  base.alias_method_chain :retrieve_connection_pool, :dynashard
5
5
  end
6
-
6
+
7
7
  # Set an connection pool entry for the model class pointing at
8
8
  # the shard class's pool.
9
9
  # :nodoc:
@@ -14,27 +14,12 @@ module Dynashard
14
14
  @connection_pools[model_class] = @connection_pools[shard_class]
15
15
  end
16
16
 
17
- # Return a connection pool for the specified class. If sharding
18
- # is enabled, the correct pool for the configured sharding context
19
- # will be used.
20
- #
21
- # :nodoc:
22
- # Reflection classes generated for an association proxy will
23
- # respond to :dynashard_klass and return a class with an
24
- # established connection to the correct shard.
25
- #
26
- # Sharded models will have a dynashard context defined, which
27
- # can be used as a key to the Dynashard.shard_context hash to
28
- # access the shard's connection specification.
17
+ # Return a connection pool for the specified class. If the class
18
+ # is a Dynashard generated model subclass, return the connection
19
+ # for its shard class.
29
20
  def retrieve_connection_pool_with_dynashard(klass)
30
21
  if klass.respond_to?(:dynashard_klass)
31
22
  retrieve_connection_pool_without_dynashard(klass.dynashard_klass)
32
- elsif klass.sharding_enabled?
33
- spec = Dynashard.shard_context[klass.dynashard_context]
34
- raise "Missing #{klass.dynashard_context} shard context for #{klass.name}" if spec.nil?
35
- spec = spec.call if spec.respond_to?(:call)
36
- shard_klass = Dynashard.class_for(spec)
37
- retrieve_connection_pool_without_dynashard(shard_klass)
38
23
  else
39
24
  retrieve_connection_pool_without_dynashard(klass)
40
25
  end
@@ -8,6 +8,7 @@ module Dynashard
8
8
  alias_method_chain :instantiate, :dynashard
9
9
  alias_method_chain :create, :dynashard
10
10
  alias_method_chain :arel_engine, :dynashard
11
+ alias_method_chain :connection, :dynashard
11
12
  end
12
13
  end
13
14
 
@@ -124,6 +125,19 @@ module Dynashard
124
125
  create_without_dynashard(attributes, &block)
125
126
  end
126
127
  end
128
+
129
+ # For sharded models, return the shard class's connection
130
+ #
131
+ # > conn = Dynashard.with_context(:owner => 'shard1'){ShardedModel.connection}
132
+ # > conn == Dynashard::Shard0.connection
133
+ # => true
134
+ def connection_with_dynashard
135
+ if sharding_enabled?
136
+ dynashard_sharded_subclass.connection
137
+ else
138
+ connection_without_dynashard
139
+ end
140
+ end
127
141
  end
128
142
  end
129
143
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynashard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Hengeveld
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-14 00:00:00 -08:00
18
+ date: 2011-02-17 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency