Module: Lockbox::ActiveStorageExtensions::AttachedMany

Defined in:
lib/lockbox/active_storage_extensions.rb

Instance Method Summary collapse

Instance Method Details

#rotate_encryption!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/lockbox/active_storage_extensions.rb', line 47

def rotate_encryption!
  raise "Not encrypted" unless encrypted?

  # must call to_a - do not change
  previous_attachments = attachments.to_a

  attachables =
    previous_attachments.map do |attachment|
      Utils.rebuild_attachable(attachment)
    end

  ActiveStorage::Attachment.transaction do
    attach(attachables)
    previous_attachments.each(&:purge)
  end

  attachments.reload

  true
end