Sha256: b0a7f7e1b3cf1e2a0219e0c49027c0ca58b9f0d3d55961460425808c4e7f410c

Contents?: true

Size: 862 Bytes

Versions: 45

Compression:

Stored size: 862 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the features needed when you want a model to be able to create
  # links from it to another resource.
  module HasAttachments
    extend ActiveSupport::Concern

    included do
      has_many :attachments,
               class_name: "Decidim::Attachment",
               dependent: :destroy,
               inverse_of: :attached_to,
               as: :attached_to

      # All the attachments that are photos for this process.
      #
      # Returns an Array<Attachment>
      def photos
        @photos ||= attachments.select(&:photo?)
      end

      # All the attachments that are documents for this process.
      #
      # Returns an Array<Attachment>
      def documents
        @documents ||= attachments.select(&:document?)
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
decidim-core-0.9.3 lib/decidim/has_attachments.rb
decidim-core-0.9.2 lib/decidim/has_attachments.rb
decidim-core-0.9.1 lib/decidim/has_attachments.rb
decidim-core-0.9.0 lib/decidim/has_attachments.rb
decidim-core-0.8.4 lib/decidim/has_attachments.rb
decidim-core-0.8.3 lib/decidim/has_attachments.rb
decidim-core-0.8.2 lib/decidim/has_attachments.rb
decidim-core-0.8.1 lib/decidim/has_attachments.rb
decidim-core-0.8.0 lib/decidim/has_attachments.rb
decidim-core-0.7.4 lib/decidim/has_attachments.rb
decidim-core-0.7.3 lib/decidim/has_attachments.rb
decidim-core-0.7.2 lib/decidim/has_attachments.rb
decidim-core-0.7.1 lib/decidim/has_attachments.rb
decidim-core-0.7.0 lib/decidim/has_attachments.rb
decidim-core-0.6.8 lib/decidim/has_attachments.rb
decidim-0.6.8 decidim-core/lib/decidim/has_attachments.rb
decidim-core-0.6.7 lib/decidim/has_attachments.rb
decidim-0.6.7 decidim-core/lib/decidim/has_attachments.rb
decidim-core-0.6.6 lib/decidim/has_attachments.rb
decidim-0.6.6 decidim-core/lib/decidim/has_attachments.rb