Sha256: 745a3858db74d0cc947abc902c4a886888a948549554946327e5d16545726d02
Contents?: true
Size: 1.38 KB
Versions: 19
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic to update an attachment from a # participatory process. class UpdateAttachment < Rectify::Command include ::Decidim::AttachmentAttributesMethods attr_reader :attachment # Public: Initializes the command. # # attachment - the Attachment to update # form - A form object with the params. def initialize(attachment, form) @attachment = attachment @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if form.invalid? update_attachment broadcast(:ok) end private attr_reader :form def update_attachment attachment.update!(attributes) end def attributes { title: form.title, file: form.file, description: form.description, weight: form.weight, attachment_collection: form.attachment_collection }.merge( attachment_attributes(:file) ).reject do |attribute, value| value.blank? && attribute != :attachment_collection end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems