Class: Decidim::Proposals::Admin::MergeProposals

Inherits:
Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
app/commands/decidim/proposals/admin/merge_proposals.rb

Overview

A command with all the business logic when an admin merges proposals from one component to another.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ MergeProposals

Public: Initializes the command.

form - A form object with the params.



13
14
15
# File 'app/commands/decidim/proposals/admin/merge_proposals.rb', line 13

def initialize(form)
  @form = form
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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/commands/decidim/proposals/admin/merge_proposals.rb', line 23

def call
  return broadcast(:invalid) unless form.valid?

  if process_attachments?
    build_attachments
    return broadcast(:invalid) if attachments_invalid?
  end

  transaction do
    merged_proposals
  end

  broadcast(:ok, @merge_proposal)
end