Module: ActiveRecordShards::AssociationCollectionConnectionSelection

Defined in:
lib/active_record_shards/association_collection_connection_selection.rb

Defined Under Namespace

Classes: PrimaryReplicaProxy

Constant Summary collapse

MasterSlaveProxy =
PrimaryReplicaProxy

Instance Method Summary collapse

Instance Method Details

#on_primaryObject Also known as: on_master



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

def on_primary
  PrimaryReplicaProxy.new(self, :primary)
end

#on_primary_if(condition) ⇒ Object Also known as: on_master_if



15
16
17
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 15

def on_primary_if(condition)
  condition ? on_primary : self
end

#on_primary_unless(condition) ⇒ Object Also known as: on_master_unless



20
21
22
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 20

def on_primary_unless(condition)
  on_primary_if(!condition)
end

#on_replicaObject Also known as: on_slave



25
26
27
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 25

def on_replica
  PrimaryReplicaProxy.new(self, :replica)
end

#on_replica_if(condition) ⇒ Object Also known as: on_slave_if



5
6
7
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 5

def on_replica_if(condition)
  condition ? on_replica : self
end

#on_replica_unless(condition) ⇒ Object Also known as: on_slave_unless



10
11
12
# File 'lib/active_record_shards/association_collection_connection_selection.rb', line 10

def on_replica_unless(condition)
  on_replica_if(!condition)
end