Class: ConnectionManager::Using::Proxy
- Inherits:
-
Object
- Object
- ConnectionManager::Using::Proxy
- Includes:
- ActiveRecord::Querying
- 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.
26 27 28 29 30 |
# File 'lib/connection_manager/using.rb', line 26 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.
74 75 76 |
# File 'lib/connection_manager/using.rb', line 74 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.
24 25 26 |
# File 'lib/connection_manager/using.rb', line 24 def connection_class @connection_class end |
#klass ⇒ Object
Returns the value of attribute klass.
24 25 26 |
# File 'lib/connection_manager/using.rb', line 24 def klass @klass end |
Instance Method Details
#!=(compare) ⇒ Object
53 54 55 56 |
# File 'lib/connection_manager/using.rb', line 53 def != compare return @klass != compare.klass if compare.is_a?(self.class) @klass != compare end |
#==(compare) ⇒ Object
48 49 50 51 |
# File 'lib/connection_manager/using.rb', line 48 def == compare return @klass == compare.klass if compare.is_a?(self.class) @klass == compare end |
#>=(compare) ⇒ Object
43 44 45 46 |
# File 'lib/connection_manager/using.rb', line 43 def >= compare return @klass >= compare.klass if compare.is_a?(self.class) @klass >= compare end |
#connection ⇒ Object
Use the connection from the connection class
33 34 35 |
# File 'lib/connection_manager/using.rb', line 33 def connection @connection_class.connection end |
#descendants ⇒ Object
58 59 60 |
# File 'lib/connection_manager/using.rb', line 58 def descendants @klass.descendants end |
#parent ⇒ Object
66 67 68 |
# File 'lib/connection_manager/using.rb', line 66 def parent @klass.parent end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
78 79 80 |
# File 'lib/connection_manager/using.rb', line 78 def respond_to?(method_name, include_private = false) @klass.respond_to?(method_name) || super end |
#subclasses ⇒ Object
62 63 64 |
# File 'lib/connection_manager/using.rb', line 62 def subclasses @klass.subclasses end |
#superclass ⇒ Object
Make sure we return the @klass superclass, which used throughout the query building code in AR
39 40 41 |
# File 'lib/connection_manager/using.rb', line 39 def superclass @klass.superclass end |