Class: Decidim::Amendable::Promote

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/amendable/promote.rb

Overview

A command with all the business logic when a user promotes a rejected emendation.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ Promote

Public: Initializes the command.

emendation - The emendation to promote. amendable - The amendable resource.



13
14
15
16
17
18
19
# File 'app/commands/decidim/amendable/promote.rb', line 13

def initialize(form)
  @form = form
  @amendment = form.amendment
  @emendation = form.emendation
  @amendable = form.amendable
  @amender = form.amender
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 and the emendation is promoted.

  • :invalid if the transaction fails

Returns nothing.



27
28
29
30
31
32
33
34
35
36
37
# File 'app/commands/decidim/amendable/promote.rb', line 27

def call
  return broadcast(:invalid) unless form.valid? && amendment.rejected? && amender == current_user

  transaction do
    promote_emendation!
    notify_amendable_and_emendation_authors_and_followers
    link_promoted_emendation_and_proposal
  end

  broadcast(:ok, @promoted_emendation)
end