db-charmer 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/db-charmer.gemspec +7 -5
- data/lib/db_charmer.rb +3 -1
- data/lib/db_charmer/multi_db_proxy.rb +5 -1
- data/lib/db_charmer/scope_proxy.rb +17 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.2
|
data/db-charmer.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{db-charmer}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexey Kovyrin"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-28}
|
13
13
|
s.description = %q{ActiveRecord Connections Magic (slaves, multiple connections, etc)}
|
14
14
|
s.email = %q{alexey@kovyrin.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,7 +34,8 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/db_charmer/db_magic.rb",
|
35
35
|
"lib/db_charmer/finder_overrides.rb",
|
36
36
|
"lib/db_charmer/multi_db_migrations.rb",
|
37
|
-
"lib/db_charmer/multi_db_proxy.rb"
|
37
|
+
"lib/db_charmer/multi_db_proxy.rb",
|
38
|
+
"lib/db_charmer/scope_proxy.rb"
|
38
39
|
]
|
39
40
|
s.homepage = %q{http://github.com/kovyrin/db-charmer}
|
40
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -55,3 +56,4 @@ Gem::Specification.new do |s|
|
|
55
56
|
s.add_dependency(%q<rails>, [">= 2.2.0"])
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
data/lib/db_charmer.rb
CHANGED
@@ -28,6 +28,7 @@ require 'db_charmer/connection_factory'
|
|
28
28
|
require 'db_charmer/connection_proxy'
|
29
29
|
require 'db_charmer/connection_switch'
|
30
30
|
require 'db_charmer/association_proxy'
|
31
|
+
require 'db_charmer/scope_proxy'
|
31
32
|
require 'db_charmer/multi_db_proxy'
|
32
33
|
|
33
34
|
# Enable misc AR extensions
|
@@ -41,8 +42,9 @@ ActiveRecord::Base.extend(DbCharmer::MultiDbProxy::ClassMethods)
|
|
41
42
|
ActiveRecord::Base.extend(DbCharmer::MultiDbProxy::MasterSlaveClassMethods)
|
42
43
|
#ActiveRecord::Base.send(:include, DbCharmer::MultiDbProxy::InstanceMethods)
|
43
44
|
|
44
|
-
# Enable connection proxy for associations
|
45
|
+
# Enable connection proxy for associations and scopes
|
45
46
|
ActiveRecord::Associations::AssociationProxy.send(:include, DbCharmer::AssociationProxy::InstanceMethods)
|
47
|
+
ActiveRecord::NamedScope::Scope.send(:include, DbCharmer::ScopeProxy::InstanceMethods)
|
46
48
|
|
47
49
|
puts "Doing the magic..."
|
48
50
|
|
@@ -9,8 +9,12 @@ module DbCharmer
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def method_missing(meth, *args, &block)
|
12
|
+
# Switch connection and proxy the method call
|
12
13
|
@model.on_db(@slave) do |m|
|
13
|
-
m.__send__(meth, *args, &block)
|
14
|
+
res = m.__send__(meth, *args, &block)
|
15
|
+
|
16
|
+
# If result is a scope, return a new proxy for it, otherwise return the result itself
|
17
|
+
res.kind_of?(ActiveRecord::NamedScope::Scope) ? res.on_db(@slave) : res
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DbCharmer
|
2
|
+
module ScopeProxy
|
3
|
+
module InstanceMethods
|
4
|
+
def on_db(con, &block)
|
5
|
+
proxy_scope.on_db(con, self, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_slave(con = nil, &block)
|
9
|
+
proxy_scope.on_slave(con, self, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_master(&block)
|
13
|
+
proxy_scope.on_master(self, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
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.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Kovyrin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-28 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/db_charmer/finder_overrides.rb
|
51
51
|
- lib/db_charmer/multi_db_migrations.rb
|
52
52
|
- lib/db_charmer/multi_db_proxy.rb
|
53
|
+
- lib/db_charmer/scope_proxy.rb
|
53
54
|
has_rdoc: true
|
54
55
|
homepage: http://github.com/kovyrin/db-charmer
|
55
56
|
licenses: []
|