lib/lockbox/active_storage_extensions.rb in lockbox-0.1.1 vs lib/lockbox/active_storage_extensions.rb in lockbox-0.2.0

- old
+ new

@@ -8,20 +8,20 @@ protected def encrypted? # could use record_type directly # but record should already be loaded most of the time - Utils.encrypted_options(record, name).present? + !Utils.encrypted_options(record, name).nil? end def encrypt_attachable(attachable) options = Utils.encrypted_options(record, name) - box = Utils.build_box(record, options) + box = Utils.build_box(record, options, record.class.table_name, name) case attachable when ActiveStorage::Blob - raise NotImplemented, "Not supported" + raise NotImplementedError, "Not supported" when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile attachable = { io: StringIO.new(box.encrypt(attachable.read)), filename: attachable.original_filename, content_type: attachable.content_type @@ -31,11 +31,11 @@ io: StringIO.new(box.encrypt(attachable[:io].read)), filename: attachable[:filename], content_type: attachable[:content_type] } when String - raise NotImplemented, "Not supported" + raise NotImplementedError, "Not supported" else nil end attachable @@ -105,11 +105,11 @@ def download result = super options = Utils.encrypted_options(record, name) if options - result = Utils.build_box(record, options).decrypt(result) + result = Utils.build_box(record, options, record.class.table_name, name).decrypt(result) end result end @@ -119,34 +119,9 @@ end end included do after_save :mark_analyzed - end - end - - module Model - def attached_encrypted(name, **options) - class_eval do - @encrypted_attachments ||= {} - - unless respond_to?(:encrypted_attachments) - def self.encrypted_attachments - parent_attachments = - if superclass.respond_to?(:encrypted_attachments) - superclass.encrypted_attachments - else - {} - end - - parent_attachments.merge(@encrypted_attachments || {}) - end - end - - raise ArgumentError, "Duplicate encrypted attachment: #{name}" if encrypted_attachments[name] - - @encrypted_attachments[name] = options - end end end end end