read_from_slave 0.5.0 → 0.5.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/README CHANGED
@@ -114,7 +114,7 @@ The safest thing to do is to have something like this in your production.rb or e
114
114
 
115
115
  Documentation
116
116
 
117
- http://rdoc.info/projects/sdsykes/read_from_slave
117
+ http://rdoc.info/github/sdsykes/read_from_slave/master/frames
118
118
 
119
119
  Tests
120
120
 
data/README.textile CHANGED
@@ -142,7 +142,7 @@ end
142
142
 
143
143
  h2. Documentation
144
144
 
145
- "http://rdoc.info/projects/sdsykes/read_from_slave":http://rdoc.info/projects/sdsykes/read_from_slave
145
+ "http://rdoc.info/github/sdsykes/read_from_slave/master/frames":http://rdoc.info/github/sdsykes/read_from_slave/master/frames
146
146
 
147
147
  h2. Tests
148
148
 
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :minor: 5
3
3
  :build:
4
4
  :major: 0
5
- :patch: 0
5
+ :patch: 1
@@ -0,0 +1,10 @@
1
+ require 'read_from_slave'
2
+ require 'rails'
3
+
4
+ module ReadFromSlave
5
+ class Railtie < Rails::Railtie
6
+ initializer 'read_from_slave.install_with_methods', :after=>"active_record.initialize_database" do |app|
7
+ ReadFromSlave.install_with_methods!
8
+ end
9
+ end
10
+ end
@@ -82,6 +82,20 @@ module ReadFromSlave
82
82
  end
83
83
  end
84
84
 
85
+ def install_with_methods!
86
+ ActiveRecord::Base.connection.instance_variable_get(:@config)[:slaves].each_key do |slave_name|
87
+ ActiveRecord::Base.class_eval <<-EOM
88
+ def self.with_#{slave_name}(&block)
89
+ Thread.current[:with_#{slave_name}_count] ||= 0
90
+ Thread.current[:with_#{slave_name}_count] += 1
91
+ yield
92
+ ensure
93
+ Thread.current[:with_#{slave_name}_count] -= 1
94
+ end
95
+ EOM
96
+ end if ActiveRecord::Base.connection.instance_variable_get(:@config)[:slaves]
97
+ end
98
+
85
99
  def default_to_master!
86
100
  base = ActiveRecord::Base
87
101
  base.class_eval do
@@ -121,18 +135,6 @@ module ReadFromSlave
121
135
  Thread.current[:read_from_slave] = false
122
136
  end
123
137
 
124
- ActiveRecord::Base.connection.instance_variable_get(:@config)[:slaves].each_key do |slave_name|
125
- eval <<-EOM
126
- def with_#{slave_name}(&block)
127
- Thread.current[:with_#{slave_name}_count] ||= 0
128
- Thread.current[:with_#{slave_name}_count] += 1
129
- yield
130
- ensure
131
- Thread.current[:with_#{slave_name}_count] -= 1
132
- end
133
- EOM
134
- end if ActiveRecord::Base.connection.instance_variable_get(:@config)[:slaves]
135
-
136
138
  def connection_with_slave_db_scope
137
139
  slaves.each_key do |slave_name|
138
140
  if Thread.current[:"with_#{slave_name}_count"].to_i > 0
@@ -247,3 +249,8 @@ module ReadFromSlave
247
249
  end
248
250
 
249
251
  ReadFromSlave.install!
252
+ if defined? ::Rails::Railtie
253
+ require 'read_from_slave/railtie'
254
+ else
255
+ ReadFromSlave.install_with_methods!
256
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: read_from_slave
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
4
+ prerelease:
5
+ version: 0.5.1
11
6
  platform: ruby
12
7
  authors:
13
8
  - Stephen Sykes
@@ -15,8 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-01 00:00:00 +03:00
19
- default_executable:
13
+ date: 2011-06-01 00:00:00 Z
20
14
  dependencies: []
21
15
 
22
16
  description: Read_from_slave for Rails enables database reads from a slave database, while writes continue to go to the master
@@ -34,6 +28,7 @@ files:
34
28
  - Rakefile
35
29
  - VERSION.yml
36
30
  - lib/read_from_slave.rb
31
+ - lib/read_from_slave/railtie.rb
37
32
  - test/active_record_setup.rb
38
33
  - test/helper.rb
39
34
  - test/models/course.rb
@@ -41,7 +36,6 @@ files:
41
36
  - test/schema/schema.rb
42
37
  - test/setup.rb
43
38
  - test/test.rb
44
- has_rdoc: true
45
39
  homepage: http://github.com/sdsykes/read_from_slave
46
40
  licenses: []
47
41
 
@@ -55,23 +49,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
49
  requirements:
56
50
  - - ">="
57
51
  - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
52
  version: "0"
62
53
  required_rubygems_version: !ruby/object:Gem::Requirement
63
54
  none: false
64
55
  requirements:
65
56
  - - ">="
66
57
  - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
58
  version: "0"
71
59
  requirements: []
72
60
 
73
61
  rubyforge_project:
74
- rubygems_version: 1.3.7
62
+ rubygems_version: 1.8.5
75
63
  signing_key:
76
64
  specification_version: 3
77
65
  summary: Read_from_slave - Utilise your slave databases with rails