acts_as_readonlyable 0.0.5 → 0.0.6
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 +6 -1
- data/lib/acts_as_readonlyable.rb +15 -6
- metadata +2 -2
data/README
CHANGED
@@ -40,7 +40,7 @@ dbs:
|
|
40
40
|
host: slave-host
|
41
41
|
|
42
42
|
|
43
|
-
Note: There is no need for more than one read-only database configuration in your database.yml since you can leverage traditional load balancing solutions for slaves. If you still want to use database.yml to spread the load, define multiple entries there and use acts_as_readonlyable [:first_read_only, :second_read_only]
|
43
|
+
Note: There is no need for more than one read-only database configuration in your database.yml since you can leverage traditional load balancing solutions for slaves. If you still want to use database.yml to spread the load, define multiple entries there and use acts_as_readonlyable [:first_read_only, :second_read_only].
|
44
44
|
|
45
45
|
=== Sample Model
|
46
46
|
|
@@ -58,6 +58,11 @@ r.reload # executes against the read_only db
|
|
58
58
|
r.reload(:readonly => false) # executes against the read_write db
|
59
59
|
|
60
60
|
|
61
|
+
=== Transactional Tests Support
|
62
|
+
|
63
|
+
Since there are two connections established, it breaks transactional tests that rely on the fact that all code lives within a single transaction/connection. To address that, the read only mode is disabled when there is no read-only database configuration entry defined in database.yml. In this case the warning is printed to the log file.
|
64
|
+
|
65
|
+
|
61
66
|
== Installation
|
62
67
|
|
63
68
|
As plugin:
|
data/lib/acts_as_readonlyable.rb
CHANGED
@@ -13,16 +13,25 @@ module ActiveRecord::Acts::ActsAsReadonlyable
|
|
13
13
|
def acts_as_readonlyable(*readonly_dbs)
|
14
14
|
@readonly_dbs = readonly_dbs.flatten.collect(&:to_s)
|
15
15
|
@readonly_models = readonly_classes(@readonly_dbs)
|
16
|
-
|
17
|
-
|
16
|
+
if @readonly_models.empty?
|
17
|
+
logger.warn("Read only mode is not activated for #{ self }")
|
18
|
+
else
|
19
|
+
self.extend(FinderClassOverrides)
|
20
|
+
end
|
21
|
+
self.send(:include, FinderInstanceOverrides)
|
18
22
|
end
|
19
23
|
|
20
24
|
private
|
21
25
|
|
22
26
|
def readonly_classes(dbs)
|
23
|
-
dbs.
|
24
|
-
|
25
|
-
|
27
|
+
dbs.inject([]) do |classes, db|
|
28
|
+
if configurations[RAILS_ENV][db]
|
29
|
+
define_readonly_class(db) unless ActiveRecord.const_defined?(readonly_class_name(db))
|
30
|
+
classes << ActiveRecord.const_get(readonly_class_name(db))
|
31
|
+
else
|
32
|
+
logger.warn("No db config entry defined for #{ db }")
|
33
|
+
end
|
34
|
+
classes
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
@@ -110,7 +119,7 @@ module ActiveRecord::Acts::ActsAsReadonlyable
|
|
110
119
|
|
111
120
|
end
|
112
121
|
|
113
|
-
module
|
122
|
+
module FinderInstanceOverrides
|
114
123
|
|
115
124
|
# backport from 1.2.3 for 1.1.6
|
116
125
|
def reload(options = nil)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: acts_as_readonlyable
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.6
|
7
|
+
date: 2007-06-07 00:00:00 -04:00
|
8
8
|
summary: acts_as_readonlyable allows to add read-only slaves DBs to models
|
9
9
|
require_paths:
|
10
10
|
- lib
|