Module: Lockbox::Model::Attached

Defined in:
lib/lockbox/model.rb

Instance Method Summary collapse

Instance Method Details

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



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/lockbox/model.rb', line 541

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