switch_point 0.4.1 → 0.4.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: b1f2d543d57d381bd1f30ada661a2bd0af01de56
4
- data.tar.gz: 18b2322fdead64b792dbc5bde8ea8b4a08c38ffe
3
+ metadata.gz: 77687087fa3661aba6aace55de51de3f92de2e93
4
+ data.tar.gz: ec806bac134278e915188fa93d988d640b8e50ac
5
5
  SHA512:
6
- metadata.gz: 276be82faa7bdb01ab7c15959c6ef226433c5296ebfc4cf3e3b081ef3e162bf3b342c1ced86ed72985589a5d447a049bf04f4a44595ab1cd63e6be605d129a1a
7
- data.tar.gz: 5affb3b76703ee30e84714e388a9c742c5444c66e5ffd71be91e48b2dcb206831172c520bea7ffae9b833c62725f1091877b4dd0a036fc5df254549aefd15b0f
6
+ metadata.gz: e5d6a8c24fa34a4cdefd0e87786c62bc9e861beb2d848478445cb9329362b9457bfdfe06f64ad27c451a21731feddd2a7a7d70b9d4b6a361c9177701640a6a9c
7
+ data.tar.gz: 90bcacff53ac17022d2494584c564daa56942f978e30fd7c0322a93063f7a193b057d241a2837767b043bae06a6f79dd96c43fc95cfa0d3cd7232333d4d9efd4
@@ -1,3 +1,7 @@
1
+ ## 0.4.2 (2014-06-19)
2
+ - Establish connection lazily
3
+ - Just like ActiveRecord::Base, real connection isn't created until `.connection` is called
4
+
1
5
  ## 0.4.1 (2014-06-19)
2
6
  - Support :writable only configuration
3
7
 
@@ -8,7 +8,7 @@ module SwitchPoint
8
8
  DESTRUCTIVE_METHODS.each do |method_name|
9
9
  define_method(:"#{method_name}_with_switch_point") do |*args, &block|
10
10
  parent_method = :"#{method_name}_without_switch_point"
11
- if self.pool.equal?(ActiveRecord::Base.connection.pool)
11
+ if self.pool.equal?(ActiveRecord::Base.connection_pool)
12
12
  Connection.handle_base_connection(self, parent_method, *args, &block)
13
13
  else
14
14
  Connection.handle_generated_connection(self, parent_method, method_name, *args, &block)
@@ -10,7 +10,7 @@ module SwitchPoint
10
10
  @current_name = name
11
11
  AVAILABLE_MODES.each do |mode|
12
12
  model = define_model(name, mode)
13
- memorize_switch_point(name, mode, model.connection)
13
+ memorize_switch_point(name, mode, model.connection_pool)
14
14
  end
15
15
  @global_mode = DEFAULT_MODE
16
16
  end
@@ -30,10 +30,9 @@ module SwitchPoint
30
30
  end
31
31
  end
32
32
 
33
- def memorize_switch_point(name, mode, connection)
33
+ def memorize_switch_point(name, mode, pool)
34
34
  switch_point = { name: name, mode: mode }
35
- pool = connection.pool
36
- if pool.equal?(ActiveRecord::Base.connection.pool)
35
+ if pool.equal?(ActiveRecord::Base.connection_pool)
37
36
  if mode != :writable
38
37
  raise RuntimeError.new("ActiveRecord::Base's switch_points must be writable, but #{name} is #{mode}")
39
38
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchPoint
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -73,3 +73,12 @@ ActiveRecord::Base.configurations = {
73
73
  'default' => base.merge(database: 'default.sqlite3')
74
74
  }
75
75
  ActiveRecord::Base.establish_connection(:default)
76
+
77
+ # XXX: Check connection laziness
78
+ [Book, User, Note, Nanika1, ActiveRecord::Base].each do |model|
79
+ model.with_writable do
80
+ if model.connected?
81
+ raise "#{model.name} didn't establish connection lazily!"
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switch_point
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki