Class: ActiveRecordShards::AssociationCollectionConnectionSelection::PrimaryReplicaProxy

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) ⇒ PrimaryReplicaProxy

Returns a new instance of PrimaryReplicaProxy.



30
31
32
33
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 30

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

rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing



35
36
37
38
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 35

def method_missing(method, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
  reflection = @association_collection.proxy_association.reflection
  reflection.klass.on_cx_switch_block(@which) { @association_collection.send(method, *args, &block) }
end