Class: DbCharmer::ConnectionProxy
- Inherits:
-
ActiveSupport::BasicObject
- Defined in:
- lib/db_charmer/connection_proxy.rb
Constant Summary
collapse
- RESPOND_TO_METHODS =
[
:abstract_connection_class,
:db_charmer_connection_name,
:db_charmer_connection_proxy,
:db_charmer_retrieve_connection,
:nil?
].freeze
- DOESNT_RESPOND_TO_METHODS =
Short-circuit some of the methods for which we know there is a separate check in coercion code
[
:set_real_connection
].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(abstract_class, db_name) ⇒ ConnectionProxy
Returns a new instance of ConnectionProxy.
10
11
12
13
|
# File 'lib/db_charmer/connection_proxy.rb', line 10
def initialize(abstract_class, db_name)
@abstract_connection_class = abstract_class
@db_name = db_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
52
53
54
|
# File 'lib/db_charmer/connection_proxy.rb', line 52
def method_missing(meth, *args, &block)
db_charmer_retrieve_connection.send(meth, *args, &block)
end
|
Instance Attribute Details
#abstract_connection_class ⇒ Object
We use this to get a connection class from the proxy
8
9
10
|
# File 'lib/db_charmer/connection_proxy.rb', line 8
def abstract_connection_class
@abstract_connection_class
end
|
Instance Method Details
#db_charmer_connection_name ⇒ Object
15
16
17
|
# File 'lib/db_charmer/connection_proxy.rb', line 15
def db_charmer_connection_name
@db_name
end
|
#db_charmer_connection_proxy ⇒ Object
19
20
21
|
# File 'lib/db_charmer/connection_proxy.rb', line 19
def db_charmer_connection_proxy
self
end
|
#db_charmer_retrieve_connection ⇒ Object
23
24
25
|
# File 'lib/db_charmer/connection_proxy.rb', line 23
def db_charmer_retrieve_connection
@abstract_connection_class.retrieve_connection
end
|
#nil? ⇒ Boolean
27
28
29
|
# File 'lib/db_charmer/connection_proxy.rb', line 27
def nil?
false
end
|
#respond_to?(method_name, include_all = false) ⇒ Boolean
45
46
47
48
49
|
# File 'lib/db_charmer/connection_proxy.rb', line 45
def respond_to?(method_name, include_all = false)
return true if RESPOND_TO_METHODS.include?(method_name)
return false if DOESNT_RESPOND_TO_METHODS.include?(method_name)
db_charmer_retrieve_connection.respond_to?(method_name, include_all)
end
|