Class: Searls::Auth::UpdatesSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/searls/auth/updates_settings.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(user:, params:) ⇒ UpdatesSettings

Returns a new instance of UpdatesSettings.



12
13
14
15
16
17
# File 'lib/searls/auth/updates_settings.rb', line 12

def initialize(user:, params:)
  @user = user
  @params = params || {}
  @errors = []
  @password_changed = false
end

Instance Method Details

#updateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/searls/auth/updates_settings.rb', line 19

def update
  enforce_current_password_requirement

  handle_password_change if errors.empty?

  return failure_result unless errors.empty?

  if changes_applied?
    if user.save
      Result.new(
        success?: true,
        user: user,
        errors: [],
        password_changed?: @password_changed
      )
    else
      Result.new(
        success?: false,
        user: user,
        errors: simplified_error_messages(user)
      )
    end
  else
    Result.new(success?: true, user: user, errors: [], password_changed?: false)
  end
end