Module: Switchman::ActiveRecord::Persistence

Defined in:
lib/switchman/active_record/persistence.rb

Instance Method Summary collapse

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

#deleteObject



17
18
19
20
# File 'lib/switchman/active_record/persistence.rb', line 17

def delete
  db = shard.database_server
  db.unguard { super }
end

#destroyObject



22
23
24
25
# File 'lib/switchman/active_record/persistence.rb', line 22

def destroy
  writable_shadow_record_warning
  super
end

#reloadObject



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

#touchObject

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_columnsObject



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_warningObject



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