acts_as_readonlyable 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -3
- data/lib/acts_as_readonlyable.rb +6 -5
- metadata +3 -3
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
== Introduction
|
2
2
|
|
3
|
-
ActsAsReadonlyable adds support of multiple read-only slave databases to ActiveRecord models. When a model is marked with acts_as_readonlyable, some of AR finders are overridden to run against a slave DB. The supported finders are find, find_by_sql, count_by_sql, find_[all_]by_*, and
|
3
|
+
ActsAsReadonlyable adds support of multiple read-only slave databases to ActiveRecord models. When a model is marked with acts_as_readonlyable, some of AR finders are overridden to run against a slave DB. The supported finders are find, find_by_sql, count_by_sql, find_[all_]by_*, and calculations.
|
4
4
|
|
5
5
|
Finders can be forced to fall back to a default DB by passing the :readonly flag set to 'false'.
|
6
6
|
|
@@ -54,8 +54,8 @@ r = Fruit.find(:first) # executes against the read_only db
|
|
54
54
|
r.field = 'value'
|
55
55
|
r.save! # executes against the read_write db
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
Fruit.count # executes against the read_only db
|
58
|
+
Fruit.count(:readonly => false) # executes against the read_write db
|
59
59
|
|
60
60
|
|
61
61
|
=== Transactional Tests Support
|
data/lib/acts_as_readonlyable.rb
CHANGED
@@ -41,8 +41,8 @@ module ActiveRecord::Acts::ActsAsReadonlyable
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def define_readonly_class(db)
|
44
|
-
|
45
|
-
class
|
44
|
+
ActiveRecord.module_eval %Q!
|
45
|
+
class #{ readonly_class_name(db) } < Base
|
46
46
|
self.abstract_class = true
|
47
47
|
establish_connection configurations[RAILS_ENV]['#{ db }']
|
48
48
|
end
|
@@ -104,7 +104,7 @@ module ActiveRecord::Acts::ActsAsReadonlyable
|
|
104
104
|
private
|
105
105
|
|
106
106
|
def run_on_db(options)
|
107
|
-
if with_readonly?(options)
|
107
|
+
if ((Thread.current['open_transactions'] || 0) == 0) and with_readonly?(options)
|
108
108
|
run_on_readonly_db { yield }
|
109
109
|
else
|
110
110
|
yield
|
@@ -132,8 +132,9 @@ module ActiveRecord::Acts::ActsAsReadonlyable
|
|
132
132
|
|
133
133
|
module FinderInstanceOverrides
|
134
134
|
|
135
|
-
# backport from 1.2.3 for 1.1.6
|
136
|
-
def reload(options =
|
135
|
+
# backport from 1.2.3 for 1.1.6 + disable readonly by default for reload - replication lag
|
136
|
+
def reload(options = {})
|
137
|
+
options[:readonly] = false unless options.has_key?(:readonly)
|
137
138
|
clear_aggregation_cache
|
138
139
|
clear_association_cache
|
139
140
|
@attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes'))
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
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.9
|
7
|
+
date: 2007-09-22 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
|