decisiv-sharded_database 0.2.0.1 → 0.2.0.2
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.
@@ -0,0 +1,44 @@
|
|
1
|
+
module ShardedDatabase
|
2
|
+
module ModelWithConnection
|
3
|
+
|
4
|
+
def self.included(klass)
|
5
|
+
klass.extend ClassMethods
|
6
|
+
|
7
|
+
klass.class_eval do
|
8
|
+
class << self
|
9
|
+
alias_method_chain :find, :connection
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.borrow_connection(requesting_class, target_class, &block)
|
15
|
+
eigen = requesting_class.metaclass
|
16
|
+
eigen.delegate :connection, :to => target_class
|
17
|
+
yield(requesting_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
|
23
|
+
def find_with_connection(*args)
|
24
|
+
if args.last.is_a?(Hash) && connection_arg = args.last.delete(:connection)
|
25
|
+
connection =
|
26
|
+
case connection_arg
|
27
|
+
when Symbol then send(connection_arg, *args)
|
28
|
+
when Proc then connection_arg.call(*args)
|
29
|
+
else connection_arg
|
30
|
+
end
|
31
|
+
ModelWithConnection.borrow_connection(self, connection) { find_without_connection(*args) }
|
32
|
+
else
|
33
|
+
find_without_connection(*args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
module InstanceMethods
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
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.2.0.
|
4
|
+
version: 0.2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brennan Dunn
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/sharded_database/aggregate.rb
|
30
30
|
- lib/sharded_database/aggregate_proxy.rb
|
31
31
|
- lib/sharded_database/core_extensions.rb
|
32
|
+
- lib/sharded_database/model_with_connection.rb
|
32
33
|
has_rdoc: true
|
33
34
|
homepage: http://github.com/brennandunn/sharded_database/
|
34
35
|
post_install_message:
|