Class: Decidim::Admin::UpdateCategory

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

Overview

A command with all the business logic when updating a category in the system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(category, form, user) ⇒ UpdateCategory

Public: Initializes the command.

category - the Category to update form - A form object with the params.



14
15
16
17
18
# File 'decidim-admin/app/commands/decidim/admin/update_category.rb', line 14

def initialize(category, form, user)
  @category = category
  @form = form
  @user = user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



8
9
10
# File 'decidim-admin/app/commands/decidim/admin/update_category.rb', line 8

def category
  @category
end

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.



26
27
28
29
30
31
# File 'decidim-admin/app/commands/decidim/admin/update_category.rb', line 26

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

  update_category
  broadcast(:ok)
end