Method: Lockbox::ActiveStorageExtensions::Attachment#open
- Defined in:
- lib/lockbox/active_storage_extensions.rb
#open(**options) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/lockbox/active_storage_extensions.rb', line 128 def open(**) blob.open(**) do |file| = Utils.(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 = && (![:migrating] || blob.["encrypted"]) if encrypted result = Utils.decrypt_result(record, name, , 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 |