Class: Decidim::Initiatives::Admin::UpdateInitiativeType

Inherits:
Command
  • Object
show all
Includes:
AttachmentAttributesMethods
Defined in:
decidim-initiatives/app/commands/decidim/initiatives/admin/update_initiative_type.rb

Overview

A command with all the business logic that updates an existing initiative type.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(initiative_type, form, user) ⇒ UpdateInitiativeType

Public: Initializes the command.

initiative_type: Decidim::InitiativesType form - A form object with the params.



15
16
17
18
19
# File 'decidim-initiatives/app/commands/decidim/initiatives/admin/update_initiative_type.rb', line 15

def initialize(initiative_type, form, user)
  @form = form
  @initiative_type = initiative_type
  @user = 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.

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

Returns nothing.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'decidim-initiatives/app/commands/decidim/initiatives/admin/update_initiative_type.rb', line 27

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

  Decidim.traceability.perform_action!("update", initiative_type, @user) do
    initiative_type.update(attributes)

    if initiative_type.valid?
      update_initiatives_signature_type
      broadcast(:ok, initiative_type)
    else
      broadcast(:invalid)
    end
  end
end