lib/lockbox/active_storage_extensions.rb in lockbox-1.4.1 vs lib/lockbox/active_storage_extensions.rb in lockbox-2.0.0

- old
+ new

@@ -32,40 +32,20 @@ Utils.encrypt_attachable(record, name, attachable) end end module AttachedOne - if ActiveStorage::VERSION::MAJOR < 6 - def attach(attachable) - attachable = encrypt_attachable(attachable) if encrypted? - super(attachable) - end - end - def rotate_encryption! raise "Not encrypted" unless encrypted? attach(Utils.rebuild_attachable(self)) if attached? true end end module AttachedMany - if ActiveStorage::VERSION::MAJOR < 6 - def attach(*attachables) - if encrypted? - attachables = - attachables.flatten.collect do |attachable| - encrypt_attachable(attachable) - end - end - - super(attachables) - end - end - def rotate_encryption! raise "Not encrypted" unless encrypted? # must call to_a - do not change previous_attachments = attachments.to_a @@ -129,30 +109,28 @@ blob.instance_variable_set(:@lockbox_encrypted, true) if Utils.encrypted_options(record, name) super end end - if ActiveStorage::VERSION::MAJOR >= 6 - def open(**options) - blob.open(**options) do |file| - options = Utils.encrypted_options(record, name) - # only trust the metadata when migrating - # as earlier versions of Lockbox won't have it - # and it's not a good practice to trust modifiable data - encrypted = options && (!options[:migrating] || blob.metadata["encrypted"]) - if encrypted - result = Utils.decrypt_result(record, name, options, file.read) - file.rewind - # truncate may not be available on all platforms - # according to the Ruby docs - # may need to create a new temp file instead - file.truncate(0) - file.write(result) - file.rewind - end - - yield file + def open(**options) + blob.open(**options) do |file| + options = Utils.encrypted_options(record, name) + # only trust the metadata when migrating + # as earlier versions of Lockbox won't have it + # and it's not a good practice to trust modifiable data + encrypted = options && (!options[:migrating] || blob.metadata["encrypted"]) + if encrypted + result = Utils.decrypt_result(record, name, options, file.read) + file.rewind + # truncate may not be available on all platforms + # according to the Ruby docs + # may need to create a new temp file instead + file.truncate(0) + file.write(result) + file.rewind end + + yield file end end end module Blob