Class: ActiveRecordShards::AssociationCollectionConnectionSelection::MasterSlaveProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_shards/association_collection_connection_selection.rb

Instance Method Summary collapse

Constructor Details

#initialize(association_collection, which) ⇒ MasterSlaveProxy

Returns a new instance of MasterSlaveProxy.



28
29
30
31
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 28

def initialize(association_collection, which)
  @association_collection = association_collection
  @which = which
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 33

def method_missing(method, *args, &block)
  # would love to not rely on version here, unfortunately @association_collection
  # is a sensitive little bitch of an object.
  if ActiveRecord::VERSION::STRING >= "3.1.0"
    reflection = @association_collection.proxy_association.reflection
  else
    reflection = @association_collection.proxy_reflection
  end

  reflection.klass.on_cx_switch_block(@which) { @association_collection.send(method, *args, &block) }
end