Class: Decidim::Admin::UpdateAttachment

Inherits:
Command
  • Object
show all
Includes:
Decidim::AttachmentAttributesMethods
Defined in:
decidim-admin/app/commands/decidim/admin/update_attachment.rb

Overview

A command with all the business logic to update an attachment from a participatory process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(attachment, form, user) ⇒ UpdateAttachment

Public: Initializes the command.

attachment - the Attachment to update form - A form object with the params.



16
17
18
19
20
# File 'decidim-admin/app/commands/decidim/admin/update_attachment.rb', line 16

def initialize(attachment, form, user)
  @attachment = attachment
  @form = form
  @user = user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



10
11
12
# File 'decidim-admin/app/commands/decidim/admin/update_attachment.rb', line 10

def attachment
  @attachment
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



28
29
30
31
32
33
# File 'decidim-admin/app/commands/decidim/admin/update_attachment.rb', line 28

def call
  return broadcast(:invalid) if form.invalid?

  update_attachment
  broadcast(:ok)
end