Sha256: 64c5bd26101ecad856421c721ab1a8d08a35607b0873f9866b4a08f4362e73d4

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A module with all the attachment common methods for proposals
    # and collaborative draft commands.
    module AttachmentMethods
      private

      def build_attachment
        @attachment = Attachment.new(
          title: @form.attachment.title,
          file: @form.attachment.file,
          attached_to: @attached_to
        )
      end

      def attachment_invalid?
        if attachment.invalid? && attachment.errors.has_key?(:file)
          @form.attachment.errors.add :file, attachment.errors[:file]
          true
        end
      end

      def attachment_present?
        @form.attachment.file.present?
      end

      def create_attachment
        attachment.attached_to = @attached_to
        attachment.save!
      end

      def attachments_allowed?
        @form.current_component.settings.attachments_allowed?
      end

      def process_attachments?
        attachments_allowed? && attachment_present?
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-proposals-0.21.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.20.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.20.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.19.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.18.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.19.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.17.2 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.18.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.17.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.16.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.17.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.16.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.15.2 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.15.1 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.15.0 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.14.4 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.14.3 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.14.2 app/commands/decidim/proposals/attachment_methods.rb
decidim-proposals-0.14.1 app/commands/decidim/proposals/attachment_methods.rb