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

Constructor Details

#initialize(form) ⇒ Promote

Public: Initializes the command.

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



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

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



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

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