Module: Lockbox::ActiveStorageExtensions::Model

Defined in:
lib/lockbox/active_storage_extensions.rb

Instance Method Summary collapse

Instance Method Details

#attached_encrypted(name, **options) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/lockbox/active_storage_extensions.rb', line 128

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