Class: Decidim::Amendable::Withdraw

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

Overview

A command with all the business logic to withdraw an amendment.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(amendment, current_user) ⇒ Withdraw

Public: Initializes the command.

amendment - The amendment to withdraw. current_user - The current user.



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

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

  • :invalid if the resource already has votes or does not belong to current user.

Returns nothing.



24
25
26
27
28
29
30
31
32
33
# File 'app/commands/decidim/amendable/withdraw.rb', line 24

def call
  return broadcast(:invalid) unless emendation.votes.empty? && amender == current_user

  transaction do
    withdraw_amendment!
    notify_emendation_state_change!
  end

  broadcast(:ok, emendation)
end