Class: Decidim::Elections::TrusteeZone::UpdateTrustee

Inherits:
Command
  • Object
show all
Defined in:
decidim-elections/app/commands/decidim/elections/trustee_zone/update_trustee.rb

Overview

This command allows the user to update their trustee information

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ UpdateTrustee

Public: Initializes the command.

form - A form with the new trustee information



11
12
13
# File 'decidim-elections/app/commands/decidim/elections/trustee_zone/update_trustee.rb', line 11

def initialize(form)
  @form = form
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Update the trustee if valid.

Broadcasts :ok if successful, :invalid otherwise.



18
19
20
21
22
23
24
25
26
27
# File 'decidim-elections/app/commands/decidim/elections/trustee_zone/update_trustee.rb', line 18

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

  update_trustee!

  broadcast(:ok, trustee)
rescue ActiveRecord::RecordNotUnique
  form.errors.add(:name, :taken)
  broadcast(:invalid)
end