lib/lockbox/active_storage_extensions.rb in lockbox-0.3.5 vs lib/lockbox/active_storage_extensions.rb in lockbox-0.3.6
- old
+ new
@@ -99,17 +99,49 @@
end
result
end
+ if ActiveStorage::VERSION::MAJOR >= 6
+ def open(**options)
+ blob.open(**options) do |file|
+ options = Utils.encrypted_options(record, name)
+ if options
+ result = 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(Utils.build_box(record, options, record.class.table_name, name).decrypt(result))
+ file.rewind
+ end
+
+ yield file
+ end
+ end
+ end
+
def mark_analyzed
if Utils.encrypted_options(record, name)
blob.update!(metadata: blob.metadata.merge(analyzed: true))
end
end
included do
after_save :mark_analyzed
+ end
+ end
+
+ module Blob
+ private
+
+ def extract_content_type(io)
+ if io.is_a?(Lockbox::IO) && io.extracted_content_type
+ io.extracted_content_type
+ else
+ super
+ end
end
end
end
end