decisiv-sharded_database 0.1.4.2 → 0.1.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/Rakefile +1 -0
- data/lib/sharded_database/aggregate.rb +25 -2
- data/lib/sharded_database/aggregate_proxy.rb +2 -26
- data/lib/sharded_database/core_extensions.rb +1 -1
- data/lib/sharded_database.rb +1 -1
- data/test/lib/database.yml +3 -3
- data/test/lib/models.rb +5 -0
- data/test/sharded_database/association_test.rb +4 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ module ShardedDatabase
|
|
21
21
|
|
22
22
|
def find_with_raw(*args)
|
23
23
|
@raw = args.last.is_a?(Hash) && args.last.delete(:raw)
|
24
|
-
@raw ?
|
24
|
+
@raw ? temporarily_undef_method(:after_find) { find_without_raw(*args) } : find_without_raw(*args)
|
25
25
|
end
|
26
26
|
|
27
27
|
def preserve_attributes(*attrs)
|
@@ -55,10 +55,33 @@ module ShardedDatabase
|
|
55
55
|
undef_method(m) unless m =~ /^__|proxy_|inspect/
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
self.class.reflect_on_all_associations.each do |a|
|
60
60
|
metaclass.send :alias_method, "proxy_#{a.name}".to_sym, a.name.to_sym
|
61
61
|
metaclass.send :undef_method, a.name
|
62
|
+
|
63
|
+
load_target.metaclass.send(:attr_accessor, :source_class)
|
64
|
+
load_target.source_class = @klass
|
65
|
+
method = a.name
|
66
|
+
load_target.class_eval %{
|
67
|
+
def #{method}(*args)
|
68
|
+
return @#{method} if @#{method}
|
69
|
+
|
70
|
+
if proxy_#{method}.respond_to?(:proxy_reflection)
|
71
|
+
proxy_#{method}.proxy_reflection.klass.metaclass.delegate :connection, :to => self.source_class
|
72
|
+
proxy_#{method}
|
73
|
+
else
|
74
|
+
# Hacked implementation of belongs_to to superficially simulate an association proxy
|
75
|
+
# Revisit this later and do it properly.
|
76
|
+
|
77
|
+
reflection = self.class.reflect_on_all_associations.find { |a| a.name == :#{method} }
|
78
|
+
klass = reflection.klass
|
79
|
+
klass.metaclass.delegate :connection, :to => self.source_class
|
80
|
+
@#{method} ||= klass.find(send(reflection.primary_key_name))
|
81
|
+
@#{method}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
}, __FILE__, __LINE__
|
62
85
|
end
|
63
86
|
|
64
87
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ShardedDatabase
|
2
2
|
module AggregateProxy
|
3
|
-
|
3
|
+
|
4
4
|
def ===(other)
|
5
5
|
other === load_target
|
6
6
|
end
|
@@ -21,7 +21,7 @@ module ShardedDatabase
|
|
21
21
|
|
22
22
|
def method_missing(method, *args, &block)
|
23
23
|
if association_method?(method)
|
24
|
-
apply_connection_to_association(method)
|
24
|
+
#apply_connection_to_association(method)
|
25
25
|
end
|
26
26
|
load_target.respond_to?(method) ? load_target.send(method, *args, &block) : super
|
27
27
|
end
|
@@ -35,30 +35,6 @@ module ShardedDatabase
|
|
35
35
|
eigen.delegate :connection, :to => target_class
|
36
36
|
yield(requesting_class)
|
37
37
|
end
|
38
|
-
|
39
|
-
def apply_connection_to_association(method)
|
40
|
-
load_target.metaclass.send(:attr_accessor, :source_class)
|
41
|
-
load_target.source_class = @klass
|
42
|
-
load_target.class_eval %{
|
43
|
-
def #{method}(*args)
|
44
|
-
return @#{method} if @#{method}
|
45
|
-
|
46
|
-
if proxy_#{method}.respond_to?(:proxy_reflection)
|
47
|
-
proxy_#{method}.proxy_reflection.klass.metaclass.delegate :connection, :to => self.source_class
|
48
|
-
proxy_#{method}
|
49
|
-
else
|
50
|
-
# Hacked implementation of belongs_to to superficially simulate an association proxy
|
51
|
-
# Revisit this later and do it properly.
|
52
|
-
|
53
|
-
reflection = self.class.reflect_on_all_associations.find { |a| a.name == :#{method} }
|
54
|
-
klass = reflection.klass
|
55
|
-
klass.metaclass.delegate :connection, :to => self.source_class
|
56
|
-
@#{method} ||= klass.find(send(reflection.primary_key_name))
|
57
|
-
@#{method}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
}, __FILE__, __LINE__
|
61
|
-
end
|
62
38
|
|
63
39
|
end
|
64
40
|
end
|
data/lib/sharded_database.rb
CHANGED
data/test/lib/database.yml
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
master:
|
2
2
|
adapter: mysql
|
3
|
-
database:
|
3
|
+
database: sharded_database_master
|
4
4
|
username: root
|
5
5
|
password:
|
6
6
|
host: localhost
|
7
7
|
|
8
8
|
one_db:
|
9
9
|
adapter: mysql
|
10
|
-
database:
|
10
|
+
database: sharded_database_one
|
11
11
|
username: root
|
12
12
|
password:
|
13
13
|
host: localhost
|
14
14
|
|
15
15
|
two_db:
|
16
16
|
adapter: mysql
|
17
|
-
database:
|
17
|
+
database: sharded_database_two
|
18
18
|
username: root
|
19
19
|
password:
|
20
20
|
host: localhost
|
data/test/lib/models.rb
CHANGED
@@ -30,6 +30,10 @@ class AssociationTest < ShardedDatabase::TestCase
|
|
30
30
|
assert_equal @parent.company.object_id, @parent.company.object_id
|
31
31
|
end
|
32
32
|
|
33
|
+
should 'allow instance methods to the proxied object to access associations' do
|
34
|
+
assert_equal @parent.call_company, @parent.company
|
35
|
+
end
|
36
|
+
|
33
37
|
end
|
34
38
|
|
35
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decisiv-sharded_database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brennan Dunn
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-21 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|