Class: ConnectionManager::Using::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/connection_manager/using.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, connection_class) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
9
# File 'lib/connection_manager/using.rb', line 6

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)
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.



54
55
56
# File 'lib/connection_manager/using.rb', line 54

def method_missing(name, *args, &blk)
  @klass.send(name, *args,&blk)
end

Instance Attribute Details

#connection_classObject

Returns the value of attribute connection_class.



4
5
6
# File 'lib/connection_manager/using.rb', line 4

def connection_class
  @connection_class
end

#klassObject

Returns the value of attribute klass.



4
5
6
# File 'lib/connection_manager/using.rb', line 4

def klass
  @klass
end

Instance Method Details

#!=(compare) ⇒ Object



33
34
35
36
# File 'lib/connection_manager/using.rb', line 33

def != compare
  return @klass != compare.klass if compare.is_a?(self.class)
  @klass != compare
end

#==(compare) ⇒ Object



28
29
30
31
# File 'lib/connection_manager/using.rb', line 28

def == compare
  return @klass == compare.klass if compare.is_a?(self.class)
  @klass == compare
end

#>=(compare) ⇒ Object



23
24
25
26
# File 'lib/connection_manager/using.rb', line 23

def >= compare
  return @klass >= compare.klass if compare.is_a?(self.class)
  @klass >= compare
end

#connectionObject

Use the connection from the connection class



12
13
14
15
# File 'lib/connection_manager/using.rb', line 12

def connection
  ConnectionManager.logger.info "Using proxy connection: #{@connection_class.name} for #{@klass.name}" if ConnectionManager.logger
  @connection_class.connection
end

#descendantsObject



38
39
40
# File 'lib/connection_manager/using.rb', line 38

def descendants
  @klass.descendants
end

#parentObject



46
47
48
# File 'lib/connection_manager/using.rb', line 46

def parent
  @klass.parent
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/connection_manager/using.rb', line 58

def respond_to?(method_name, include_private = false)
  @klass.respond_to?(method_name) || super
end

#subclassesObject



42
43
44
# File 'lib/connection_manager/using.rb', line 42

def subclasses
  @klass.subclasses
end

#superclassObject

Make sure we return the @klass superclass, which used throughout the query building code in AR



19
20
21
# File 'lib/connection_manager/using.rb', line 19

def superclass
  @klass.superclass
end