Class: UserManager::Update

Inherits:
Object
  • Object
show all
Defined in:
app/my_lib/user_manager/update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Update

Returns a new instance of Update.



6
7
8
9
10
11
12
13
# File 'app/my_lib/user_manager/update.rb', line 6

def initialize(user)
  if user.is_a? ::User
    self.user = user
  else
    self.user = ::User.find(user)
  end
  self.old_r_code = self.user.r_code
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



5
6
7
# File 'app/my_lib/user_manager/update.rb', line 5

def user
  @user
end

Instance Method Details

#error_messageObject



39
40
41
# File 'app/my_lib/user_manager/update.rb', line 39

def error_message
  user.errors.full_messages.uniq.to_sentence
end

#set_user_attributes(valid_params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/my_lib/user_manager/update.rb', line 15

def set_user_attributes(valid_params)
  if valid_params[:r_code].present?
    if user.r_code.present?
      valid_params.delete(:r_code)
    end
  end
  if valid_params[:phone_v2].present? && user.phone_v2_full.present?
    valid_params[:phone] = nil
  end
  user.assign_attributes valid_params
end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/my_lib/user_manager/update.rb', line 27

def update
  if user.changed?
    if user.save
      true
    else
      false
    end
  else
    true
  end
end