Class: Decidim::Amendable::Accept

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

Overview

A command with all the business logic to accept an amend.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ Accept

Public: Initializes the command.

form - A form object with the params. amendable - The resource that is being amended.



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

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

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



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

def call
  return broadcast(:invalid) if form.invalid?

  transaction do
    accept_amendment!
    update_amendable!
    notify_emendation_state_change!
    notify_amendable_and_emendation_authors_and_followers
  end

  broadcast(:ok, @emendation)
end