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

Inherits:
Rectify::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

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

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