Sha256: 20c223061e8c2f39f10e023e6bfdada9935596b330ee11b5e544959609f2e4ee

Contents?: true

Size: 1.31 KB

Versions: 29

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the components 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

      # All the attachments that are documents for this process that has a collection.
      #
      # Returns an Array<Attachment>
      def documents_with_collection
        documents.select(&:attachment_collection_id?)
      end

      # All the attachments that are documents for this process that not has a collection.
      #
      # Returns an Array<Attachment>
      def documents_without_collection
        documents.reject(&:attachment_collection_id?)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
decidim-core-0.21.0 lib/decidim/has_attachments.rb
decidim-core-0.20.1 lib/decidim/has_attachments.rb
decidim-core-0.20.0 lib/decidim/has_attachments.rb
decidim-core-0.19.1 lib/decidim/has_attachments.rb
decidim-core-0.18.1 lib/decidim/has_attachments.rb
decidim-core-0.19.0 lib/decidim/has_attachments.rb
decidim-core-0.17.2 lib/decidim/has_attachments.rb
decidim-core-0.18.0 lib/decidim/has_attachments.rb
decidim-core-0.17.1 lib/decidim/has_attachments.rb
decidim-core-0.16.1 lib/decidim/has_attachments.rb
decidim-core-0.17.0 lib/decidim/has_attachments.rb
decidim-core-0.16.0 lib/decidim/has_attachments.rb
decidim-core-0.15.2 lib/decidim/has_attachments.rb
decidim-core-0.15.1 lib/decidim/has_attachments.rb
decidim-core-0.15.0 lib/decidim/has_attachments.rb
decidim-core-0.14.4 lib/decidim/has_attachments.rb
decidim-core-0.14.3 lib/decidim/has_attachments.rb
decidim-core-0.14.2 lib/decidim/has_attachments.rb
decidim-core-0.14.1 lib/decidim/has_attachments.rb
decidim-core-0.13.1 lib/decidim/has_attachments.rb