Class: Skala::AlephAdapter::UpdateUser

Inherits:
Skala::Adapter::UpdateUser show all
Includes:
parentparent::ResolveUser
Defined in:
lib/skala/aleph_adapter/update_user.rb

Instance Attribute Summary

Attributes inherited from Skala::Adapter::Operation

#adapter

Instance Method Summary collapse

Methods inherited from Skala::Adapter::Operation

#initialize

Constructor Details

This class inherits a constructor from Skala::Adapter::Operation

Instance Method Details

#call(username, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/skala/aleph_adapter/update_user.rb', line 8

def call(username, options = {})
  username = username.upcase # ensure that username/id is always upcased
  valid_update_options = options.select { |_key, _| respond_to?("update_#{_key}", true) }.to_h

  #
  # Updating multiple properties in one go is a non trivial task, especially
  # if one of n updates fails, which implies rollbacks or partial update
  #
  if valid_update_options.keys.length > 1
    raise ArgumentError.new("Only one property can be changed within one call!")
  elsif valid_update_options.keys.length < 1
    raise ArgumentError.new("Unknown property to update!")
  end

  property_name, new_value = [valid_update_options.keys.first, valid_update_options.values.first]
  send("update_#{property_name}", username, new_value, options)
end