Class: Decidim::Proposals::Admin::CreateProposalNote

Inherits:
Command
  • Object
show all
Defined in:
decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_note.rb

Overview

A command with all the business logic when an admin creates a private note proposal.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, proposal) ⇒ CreateProposalNote

Public: Initializes the command.

form - A form object with the params. proposal - the proposal to relate.



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

def initialize(form, proposal)
  @form = form
  @proposal = proposal
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the note proposal.

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

Returns nothing.



23
24
25
26
27
28
29
30
# File 'decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_note.rb', line 23

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

  create_proposal_note
  notify_admins_and_valuators

  broadcast(:ok, proposal_note)
end