Class: ConnectionManager::Using::Proxy
- Inherits:
-
Object
- Object
- ConnectionManager::Using::Proxy
- Defined in:
- lib/connection_manager/using.rb
Instance Attribute Summary collapse
-
#connection_class ⇒ Object
Returns the value of attribute connection_class.
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #!=(compare) ⇒ Object
- #==(compare) ⇒ Object
- #>=(compare) ⇒ Object
-
#connection ⇒ Object
Use the connection from the connection class.
- #descendants ⇒ Object
-
#initialize(klass, connection_class) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(name, *args, &blk) ⇒ Object
Pass all methods to @klass, this ensures objects build from the query are the correct class and any settings in the model like table_name_prefix are used.
- #parent ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
- #subclasses ⇒ Object
-
#superclass ⇒ Object
Make sure we return the @klass superclass, which used throughout the query building code in AR.
Constructor Details
#initialize(klass, connection_class) ⇒ Proxy
Returns a new instance of Proxy.
22 23 24 25 26 |
# File 'lib/connection_manager/using.rb', line 22 def initialize(klass,connection_class) @klass = klass # the @klass from an ActiveRecord::Relation @connection_class = (connection_class.is_a?(String) ? connection_class.constantize : connection_class) ConnectionManager.logger.info "Using proxy connection: #{@connection_class.name} for #{@klass.name}" if ConnectionManager.logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
Pass all methods to @klass, this ensures objects build from the query are the correct class and any settings in the model like table_name_prefix are used.
70 71 72 |
# File 'lib/connection_manager/using.rb', line 70 def method_missing(name, *args, &blk) @klass.send(name, *args,&blk) end |
Instance Attribute Details
#connection_class ⇒ Object
Returns the value of attribute connection_class.
20 21 22 |
# File 'lib/connection_manager/using.rb', line 20 def connection_class @connection_class end |
#klass ⇒ Object
Returns the value of attribute klass.
20 21 22 |
# File 'lib/connection_manager/using.rb', line 20 def klass @klass end |
Instance Method Details
#!=(compare) ⇒ Object
49 50 51 52 |
# File 'lib/connection_manager/using.rb', line 49 def != compare return @klass != compare.klass if compare.is_a?(self.class) @klass != compare end |
#==(compare) ⇒ Object
44 45 46 47 |
# File 'lib/connection_manager/using.rb', line 44 def == compare return @klass == compare.klass if compare.is_a?(self.class) @klass == compare end |
#>=(compare) ⇒ Object
39 40 41 42 |
# File 'lib/connection_manager/using.rb', line 39 def >= compare return @klass >= compare.klass if compare.is_a?(self.class) @klass >= compare end |
#connection ⇒ Object
Use the connection from the connection class
29 30 31 |
# File 'lib/connection_manager/using.rb', line 29 def connection @connection_class.connection end |
#descendants ⇒ Object
54 55 56 |
# File 'lib/connection_manager/using.rb', line 54 def descendants @klass.descendants end |
#parent ⇒ Object
62 63 64 |
# File 'lib/connection_manager/using.rb', line 62 def parent @klass.parent end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
74 75 76 |
# File 'lib/connection_manager/using.rb', line 74 def respond_to?(method_name, include_private = false) @klass.respond_to?(method_name) || super end |
#subclasses ⇒ Object
58 59 60 |
# File 'lib/connection_manager/using.rb', line 58 def subclasses @klass.subclasses end |
#superclass ⇒ Object
Make sure we return the @klass superclass, which used throughout the query building code in AR
35 36 37 |
# File 'lib/connection_manager/using.rb', line 35 def superclass @klass.superclass end |