Module: ShardedDatabase::ModelWithConnection
- Defined in:
- lib/sharded_database/model_with_connection.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary
collapse
Class Method Details
.borrow_connection(requesting_class, target_class, &block) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/sharded_database/model_with_connection.rb', line 14
def self.borrow_connection(requesting_class, target_class, &block)
@eigen = requesting_class.metaclass
@eigen.send :alias_method, :proxy_connection, :connection
@eigen.delegate :connection, :to => target_class
yield(requesting_class)
ensure
@eigen.send :alias_method, :connection, :proxy_connection
end
|
.included(klass) ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/sharded_database/model_with_connection.rb', line 4
def self.included(klass)
klass.extend ClassMethods
klass.class_eval do
class << self
alias_method_chain :find, :connection
end
end
end
|