Module: Lockbox::Model::Attached

Defined in:
lib/lockbox/model.rb

Instance Method Summary collapse

Instance Method Details

#attached_encrypted(attribute, **options) ⇒ Object

TODO remove in future version



366
367
368
369
# File 'lib/lockbox/model.rb', line 366

def attached_encrypted(attribute, **options)
  warn "[lockbox] DEPRECATION WARNING: Use encrypts_attached instead"
  encrypts_attached(attribute, **options)
end

#encrypts_attached(*attributes, **options) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/lockbox/model.rb', line 339

def encrypts_attached(*attributes, **options)
  attributes.each do |name|
    name = name.to_sym

    class_eval do
      @lockbox_attachments ||= {}

      if @lockbox_attachments.empty?
        def self.lockbox_attachments
          parent_attachments =
            if superclass.respond_to?(:lockbox_attachments)
              superclass.lockbox_attachments
            else
              {}
            end

          parent_attachments.merge(@lockbox_attachments || {})
        end
      end

      raise "Duplicate encrypted attachment: #{name}" if lockbox_attachments[name]
      @lockbox_attachments[name] = options
    end
  end
end