Class: Decidim::Admin::ParticipatorySpace::UpdateAdmin

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

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, user_role, options = {}) ⇒ UpdateAdmin

Public: Initializes the command.

form - A form object with the params. user_role - The UserRole to update options: a hash with at least two mandatory keys, event_class and event

  • event_class - The event class to be used when notifying the user

  • event - The event name to be used when notifying the user



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

def initialize(form, user_role, options = {})
  @form = form
  @user_role = user_role
  @event_class = options.delete(:event_class)
  @event = options.delete(:event)
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
# File 'decidim-admin/app/commands/decidim/admin/participatory_space/update_admin.rb', line 27

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

  update_role!
  broadcast(:ok)
end