Class: Decidim::DestroyEphemeralUser

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

Overview

A command with all the business logic to create an ephemeral user.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(user) ⇒ DestroyEphemeralUser

Public: Initializes the command.

user - An ephemeral user.



9
10
11
# File 'decidim-core/app/commands/decidim/destroy_ephemeral_user.rb', line 9

def initialize(user)
  @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 user is not ephemeral

Returns nothing.



19
20
21
22
23
24
25
26
27
28
# File 'decidim-core/app/commands/decidim/destroy_ephemeral_user.rb', line 19

def call
  return broadcast(:invalid) unless user.ephemeral?

  destroy_pending_authorizations!
  destroy_account!

  broadcast(:ok)
rescue ActiveRecord::RecordInvalid
  broadcast(:invalid)
end