Module: Lockbox::Model::Attached

Defined in:
lib/lockbox/model.rb

Instance Method Summary collapse

Instance Method Details

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



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/lockbox/model.rb', line 655

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