Sha256: f43a661fe2c1494ffdcbb7e77ce8b124374f3ed8dee355ddd5e2cf0628527915

Contents?: true

Size: 859 Bytes

Versions: 7

Compression:

Stored size: 859 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 porcess.
      #
      # Returns an Array<Attachment>
      def photos
        @photos ||= attachments.select(&:photo?)
      end

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

Version data entries

7 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.1.0 lib/decidim/has_attachments.rb
decidim-core-0.0.8.1 lib/decidim/has_attachments.rb
decidim-core-0.0.7 lib/decidim/has_attachments.rb
decidim-core-0.0.6 lib/decidim/has_attachments.rb
decidim-core-0.0.5 lib/decidim/has_attachments.rb
decidim-core-0.0.3 lib/decidim/has_attachment.rb
decidim-core-0.0.3 lib/decidim/has_attachments.rb