knockoff 0.2.1 → 0.2.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: b71fe8eac98c6f5b545de8676314f8d993362f70
4
- data.tar.gz: 6899bcf03cc21c9bc6dc56528db0acec3efe5c44
3
+ metadata.gz: 3e5db34168c3328cc0f1103d49f8dc3afe1f1e52
4
+ data.tar.gz: 76763a62ba7a2a5328c643b2de5746349237aba1
5
5
  SHA512:
6
- metadata.gz: 208629e12804ccf7035ceffa93d3f132cf2ac82c9d0683ccb2e9b71a04f46af8a1f92f5c7349696c093a19208fb7a8e8a56d7ca6bf3cdbd504783f1b2002199f
7
- data.tar.gz: 9460406988160c910f3a5cb5ef67d74431c67713a548c187347d78ab5548c3443efa474cb8e4b528c61a6d8584b7d838864bfc5db7f593e7908466273ccbbf98
6
+ metadata.gz: 91a853b868fe982e37356c308d1ba9d882818f5294dc1fb2ba8ec8fef1414dacb6575f9c028186b46468ca6280343223812d34e498501b04508f7a769478a53b
7
+ data.tar.gz: 9492b0d7391ffabc493ff88b01950ff86c58a923c23350ad35756b1e1663ceb51eebede052754b3305aa505497287bcc64cd18ff65ba99865c2cd204d023ec0b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /spec/tmp
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/sgringwe/knockoff.svg?branch=master)](https://travis-ci.org/sgringwe/knockoff)
4
4
  [![Gem Version](https://badge.fury.io/rb/knockoff.svg)](https://badge.fury.io/rb/knockoff)
5
5
 
6
- A gem for easily using read replicas. Heavily based off of https://github.com/kenn/slavery and https://github.com/kickstarter/replica_pools gem.
6
+ A gem for easily using read replicas.
7
7
 
8
8
  ## Library Goals
9
9
 
@@ -165,6 +165,15 @@ Knockoff.establish_new_connections!({ 'pool' => db_pool })
165
165
 
166
166
  For forking servers, you may disconnect all replicas before forking with `Knockoff.disconnect_all!`.
167
167
 
168
+ ```
169
+ # puma.rb
170
+
171
+ before_fork do
172
+ ActiveRecord::Base.connection_pool.disconnect!
173
+ Knockoff.disconnect_all!
174
+ end
175
+ ```
176
+
168
177
  ### Other Cases
169
178
 
170
179
  There are likely other cases specific to each application where it makes sense to force primary database and avoid replication lag. Good candidates are time-based pages (a live calendar, for example), forms, and payments.
@@ -173,6 +182,10 @@ There are likely other cases specific to each application where it makes sense t
173
182
 
174
183
  * Do not use prepared statements with this gem
175
184
 
185
+ ## Inspirations
186
+
187
+ Heavily based off of https://github.com/kenn/slavery and https://github.com/kickstarter/replica_pools gem.
188
+
176
189
  ## Development
177
190
 
178
191
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -183,7 +196,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
183
196
 
184
197
  Bug reports and pull requests are welcome on GitHub at https://github.com/sgringwe/knockoff.
185
198
 
186
-
187
199
  ## License
188
200
 
189
201
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -11,13 +11,16 @@ module Knockoff
11
11
  private
12
12
 
13
13
  def decide_with(target)
14
- raise Knockoff::Error.new('on_slave cannot be used inside transaction block!') if inside_transaction?
14
+ calculated_target =
15
+ if Knockoff.enabled
16
+ target
17
+ else
18
+ :primary
19
+ end
15
20
 
16
- if Knockoff.enabled
17
- target
18
- else
19
- :primary
20
- end
21
+ # Don't allow setting the target to anything other than primary if we are already in a transaction
22
+ raise Knockoff::Error.new('on_replica cannot be used inside transaction block!') if calculated_target != :primary && inside_transaction?
23
+ calculated_target
21
24
  end
22
25
 
23
26
  def inside_transaction?
@@ -33,4 +36,4 @@ module Knockoff
33
36
  RequestLocals.store[:knockoff] = backup
34
37
  end
35
38
  end
36
- end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Knockoff
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knockoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord