Class: DataFabric::ConnectionProxy
- Inherits:
-
Object
- Object
- DataFabric::ConnectionProxy
show all
- Defined in:
- lib/data_fabric/ar20.rb,
lib/data_fabric/ar22.rb
Instance Method Summary
collapse
Constructor Details
#initialize(model_class, options) ⇒ ConnectionProxy
Returns a new instance of ConnectionProxy.
21
22
23
24
25
26
27
28
29
|
# File 'lib/data_fabric/ar20.rb', line 21
def initialize(model_class, options)
@model_class = model_class
@replicated = options[:replicated]
@shard_group = options[:shard_by]
@prefix = options[:prefix]
@role = 'slave' if @replicated
@model_class.send :include, ActiveRecordConnectionMethods if @replicated
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41
42
43
44
|
# File 'lib/data_fabric/ar20.rb', line 41
def method_missing(method, *args, &block)
DataFabric.log(Logger::DEBUG) { "Calling #{method} on #{connection}" }
connection.send(method, *args, &block)
end
|
Instance Method Details
#connected? ⇒ Boolean
102
103
104
|
# File 'lib/data_fabric/ar20.rb', line 102
def connected?
DataFabric.shard_active_for?(@shard_group) and cached_connections[connection_name]
end
|
#connection_name ⇒ Object
46
47
48
|
# File 'lib/data_fabric/ar20.rb', line 46
def connection_name
connection_name_builder.join('_')
end
|
#disconnect! ⇒ Object
50
51
52
53
54
55
|
# File 'lib/data_fabric/ar20.rb', line 50
def disconnect!
if connected?
connection.disconnect!
cached_connections[connection_name] = nil
end
end
|
#transaction(start_db_transaction = true, &block) ⇒ Object
37
38
39
|
# File 'lib/data_fabric/ar20.rb', line 37
def transaction(start_db_transaction = true, &block)
with_master { connection.transaction(start_db_transaction, &block) }
end
|
#verify!(arg) ⇒ Object
57
58
59
|
# File 'lib/data_fabric/ar20.rb', line 57
def verify!(arg)
connection.verify!(arg) if connected?
end
|
#with_master ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/data_fabric/ar20.rb', line 61
def with_master
old_role = @role
set_role('master')
yield
ensure
set_role(old_role)
end
|