Module: Lockbox::ActiveStorageExtensions::Attachment
- Defined in:
- lib/lockbox/active_storage_extensions.rb
Instance Method Summary collapse
- #download ⇒ Object
- #open(**options) ⇒ Object
- #preview(*args) ⇒ Object
- #transform_variants_later ⇒ Object
- #variant(*args) ⇒ Object
Instance Method Details
#download ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lockbox/active_storage_extensions.rb', line 102 def download result = super = 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, , result) end result end |
#open(**options) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/lockbox/active_storage_extensions.rb', line 135 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 |
#preview(*args) ⇒ Object
122 123 124 125 |
# File 'lib/lockbox/active_storage_extensions.rb', line 122 def preview(*args) raise Lockbox::Error, "Preview not supported for encrypted files" if Utils.(record, name) super end |
#transform_variants_later ⇒ Object
128 129 130 131 |
# File 'lib/lockbox/active_storage_extensions.rb', line 128 def transform_variants_later blob.instance_variable_set(:@lockbox_encrypted, true) if Utils.(record, name) super end |