db-charmer 1.8.3 → 1.8.4
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/CHANGES +5 -0
- data/README.rdoc +2 -2
- data/lib/db_charmer.rb +31 -20
- data/lib/db_charmer/version.rb +1 -1
- metadata +7 -7
data/CHANGES
CHANGED
data/README.rdoc
CHANGED
@@ -10,7 +10,7 @@ multiple databases and/or database servers. The major features we add to ActiveR
|
|
10
10
|
5. Multiple database migrations with very flexible query routing controls.
|
11
11
|
6. Simple database sharding functionality with multiple sharding methods (value, range, mapping table).
|
12
12
|
|
13
|
-
For more information on the project, you can check out our web site at http://
|
13
|
+
For more information on the project, you can check out our web site at http://dbcharmer.net.
|
14
14
|
|
15
15
|
|
16
16
|
== Installation
|
@@ -567,7 +567,7 @@ sharding connection names or connection configurations to be used to establish c
|
|
567
567
|
|
568
568
|
== Documentation/Questions
|
569
569
|
|
570
|
-
For more information about the library, please visit our site at http://
|
570
|
+
For more information about the library, please visit our site at http://dbcharmer.net.
|
571
571
|
If you need more defails on DbCharmer internals, please check out the source code. All the plugin's
|
572
572
|
code is ~100% covered with tests. The project located in <tt>test-project</tt> directory has unit
|
573
573
|
tests for all or, at least, the most actively used code paths.
|
data/lib/db_charmer.rb
CHANGED
@@ -10,6 +10,7 @@ module DbCharmer
|
|
10
10
|
autoload :ForceSlaveReads, 'db_charmer/action_controller/force_slave_reads'
|
11
11
|
end
|
12
12
|
|
13
|
+
#-------------------------------------------------------------------------------------------------
|
13
14
|
# Used in all Rails3-specific places
|
14
15
|
def self.rails3?
|
15
16
|
::ActiveRecord::VERSION::MAJOR > 2
|
@@ -25,42 +26,50 @@ module DbCharmer
|
|
25
26
|
::ActiveRecord::VERSION::MAJOR == 2
|
26
27
|
end
|
27
28
|
|
28
|
-
#
|
29
|
+
# Detect broken Rails version
|
29
30
|
def self.rails324?
|
30
31
|
ActiveRecord::VERSION::STRING == '3.2.4'
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
#-------------------------------------------------------------------------------------------------
|
35
|
+
# Returns true if we're running within a Rails project
|
36
|
+
def self.running_with_rails?
|
37
|
+
defined?(Rails) && Rails.respond_to?(:env)
|
38
|
+
end
|
36
39
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@@env = ENV['RAILS_ENV']
|
42
|
-
elsif ENV['RACK_ENV']
|
43
|
-
@@env = ENV['RACK_ENV']
|
44
|
-
else
|
45
|
-
@@env = 'development'
|
40
|
+
# Returns current environment name based on Rails or Rack environment variables
|
41
|
+
def self.detect_environment
|
42
|
+
return Rails.env if running_with_rails?
|
43
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
46
44
|
end
|
45
|
+
|
46
|
+
# Try to detect current environment or use development by default
|
47
|
+
@@env = DbCharmer.detect_environment
|
47
48
|
mattr_accessor :env
|
48
49
|
|
50
|
+
#-------------------------------------------------------------------------------------------------
|
51
|
+
# Accessors
|
52
|
+
@@connections_should_exist = true
|
53
|
+
mattr_accessor :connections_should_exist
|
54
|
+
|
49
55
|
def self.connections_should_exist?
|
50
56
|
!! connections_should_exist
|
51
57
|
end
|
52
58
|
|
59
|
+
#-------------------------------------------------------------------------------------------------
|
60
|
+
def self.logger
|
61
|
+
return Rails.logger if running_with_rails?
|
62
|
+
@@logger ||= Logger.new(STDERR)
|
63
|
+
end
|
64
|
+
|
65
|
+
#-------------------------------------------------------------------------------------------------
|
53
66
|
# Extend ActionController to support forcing slave reads
|
54
67
|
def self.enable_controller_magic!
|
55
68
|
::ActionController::Base.extend(DbCharmer::ActionController::ForceSlaveReads::ClassMethods)
|
56
69
|
::ActionController::Base.send(:include, DbCharmer::ActionController::ForceSlaveReads::InstanceMethods)
|
57
70
|
end
|
58
71
|
|
59
|
-
|
60
|
-
return Rails.logger if defined?(Rails)
|
61
|
-
@logger ||= Logger.new(STDERR)
|
62
|
-
end
|
63
|
-
|
72
|
+
#-------------------------------------------------------------------------------------------------
|
64
73
|
def self.with_remapped_databases(mappings, &proc)
|
65
74
|
old_mappings = ::ActiveRecord::Base.db_charmer_database_remappings
|
66
75
|
begin
|
@@ -97,6 +106,7 @@ private
|
|
97
106
|
end
|
98
107
|
end
|
99
108
|
|
109
|
+
#---------------------------------------------------------------------------------------------------
|
100
110
|
# Print warning about the broken Rails 2.3.4
|
101
111
|
puts "WARNING: Rails 3.2.4 is not officially supported by DbCharmer. Please upgrade." if DbCharmer.rails324?
|
102
112
|
|
@@ -218,8 +228,9 @@ else
|
|
218
228
|
ActiveRecord::AssociationPreload::ClassMethods.send(:public, :preload_associations)
|
219
229
|
end
|
220
230
|
|
221
|
-
|
222
|
-
|
231
|
+
#---------------------------------------------------------------------------------------------------
|
232
|
+
# Hijack connection on all new AR classes when we're in a block with main AR connection remapped
|
233
|
+
class ActiveRecord::Base
|
223
234
|
class << self
|
224
235
|
def inherited_with_hijacking(subclass)
|
225
236
|
out = inherited_without_hijacking(subclass)
|
data/lib/db_charmer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-charmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - <=
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.2.
|
21
|
+
version: 3.2.13
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - <=
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2.
|
29
|
+
version: 3.2.13
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activerecord
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - <=
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 3.2.
|
37
|
+
version: 3.2.13
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - <=
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.2.
|
45
|
+
version: 3.2.13
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,7 @@ files:
|
|
139
139
|
- README.rdoc
|
140
140
|
- LICENSE
|
141
141
|
- CHANGES
|
142
|
-
homepage: http://
|
142
|
+
homepage: http://dbcharmer.net
|
143
143
|
licenses: []
|
144
144
|
post_install_message:
|
145
145
|
rdoc_options:
|