Module: Lockbox::ActiveStorageExtensions::AttachedMany

Defined in:
lib/lockbox/active_storage_extensions.rb

Instance Method Summary collapse

Instance Method Details

#attach(*attachables) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/lockbox/active_storage_extensions.rb', line 55

def attach(*attachables)
  if encrypted?
    attachables =
      attachables.flatten.collect do |attachable|
        encrypt_attachable(attachable)
      end
  end

  super(attachables)
end

#rotate_encryption!Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lockbox/active_storage_extensions.rb', line 67

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