Class: Decidim::Meetings::WithdrawMeeting

Inherits:
Command
  • Object
show all
Defined in:
decidim-meetings/app/commands/decidim/meetings/withdraw_meeting.rb

Overview

A command with all the business logic when a user withdraws a new proposal.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(meeting, current_user) ⇒ WithdrawMeeting

Public: Initializes the command.

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



11
12
13
14
# File 'decidim-meetings/app/commands/decidim/meetings/withdraw_meeting.rb', line 11

def initialize(meeting, current_user)
  @meeting = meeting
  @current_user = 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, together with the meeting.

  • :invalid if the meeting does not belong to current user.

Returns nothing.



22
23
24
25
26
27
28
29
30
# File 'decidim-meetings/app/commands/decidim/meetings/withdraw_meeting.rb', line 22

def call
  return broadcast(:invalid) unless @meeting.authored_by?(@current_user)

  transaction do
    change_meeting_state_to_withdrawn
  end

  broadcast(:ok, @meeting)
end