Class: Decidim::Consultations::Admin::UnpublishConsultation

Inherits:
Decidim::Command show all
Defined in:
decidim-consultations/app/commands/decidim/consultations/admin/unpublish_consultation.rb

Overview

A command that sets a consultation as unpublished.

Instance Method Summary collapse

Methods inherited from Decidim::Command

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

Constructor Details

#initialize(consultation) ⇒ UnpublishConsultation

Public: Initializes the command.

consultation - A Consultation that will be unpublished


11
12
13
# File 'decidim-consultations/app/commands/decidim/consultations/admin/unpublish_consultation.rb', line 11

def initialize(consultation)
  @consultation = consultation
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.

  • :invalid if the data wasn't valid and we couldn't proceed.

Returns nothing.


21
22
23
24
25
26
# File 'decidim-consultations/app/commands/decidim/consultations/admin/unpublish_consultation.rb', line 21

def call
  return broadcast(:invalid) if consultation.nil? || !consultation.published?

  consultation.unpublish!
  broadcast(:ok)
end