Sha256: ab81c71ad7c5ee96caff0b7c7e195553573b6448fa743e8eea39790b08097442
Contents?: true
Size: 1.16 KB
Versions: 17
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module Decidim module System # A command with all the business logic when updating an admin in # the system. class UpdateAdmin < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. def initialize(admin, form) @admin = admin @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if form.invalid? update_admin broadcast(:ok) end private attr_reader :form def update_admin @admin.update_attributes!(attributes) end def attributes { email: form.email }.merge(password_attributes) end def password_attributes return {} if form.password == form.password_confirmation && form.password.blank? { password: form.password, password_confirmation: form.password_confirmation } end end end end
Version data entries
17 entries across 17 versions & 2 rubygems