Module: Switchman::ActiveRecord::Persistence
- Defined in:
- lib/switchman/active_record/persistence.rb
Instance Method Summary collapse
- #create_or_update(&block) ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #reload ⇒ Object
-
#touch ⇒ Object
touch reads the id attribute directly, so it’s not relative to the current shard.
- #update_columns ⇒ Object
- #writable_shadow_record_warning ⇒ Object
Instance Method Details
#create_or_update(&block) ⇒ Object
27 28 29 30 |
# File 'lib/switchman/active_record/persistence.rb', line 27 def create_or_update(**, &block) writable_shadow_record_warning super end |
#delete ⇒ Object
17 18 19 20 |
# File 'lib/switchman/active_record/persistence.rb', line 17 def delete db = shard.database_server db.unguard { super } end |
#destroy ⇒ Object
22 23 24 25 |
# File 'lib/switchman/active_record/persistence.rb', line 22 def destroy writable_shadow_record_warning super end |
#reload ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/switchman/active_record/persistence.rb', line 32 def reload(*) res = super # When a shadow record is reloaded the real record is returned. So # we need to ensure the loaded_from_shard is set correctly after a reload. @loaded_from_shard = @shard if @readonly_from_shadow @readonly_from_shadow = false @readonly = false end res end |
#touch ⇒ Object
touch reads the id attribute directly, so it’s not relative to the current shard
7 8 9 10 |
# File 'lib/switchman/active_record/persistence.rb', line 7 def touch(*, **) writable_shadow_record_warning shard.activate(self.class.connection_class_for_self) { super } end |
#update_columns ⇒ Object
12 13 14 15 |
# File 'lib/switchman/active_record/persistence.rb', line 12 def update_columns(*) writable_shadow_record_warning shard.activate(self.class.connection_class_for_self) { super } end |
#writable_shadow_record_warning ⇒ Object
44 45 46 47 48 |
# File 'lib/switchman/active_record/persistence.rb', line 44 def writable_shadow_record_warning return unless shadow_record? && Switchman.config[:writable_shadow_records] Switchman::Deprecation.warn("writing to shadow records is not supported") end |