Class: User

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/user.rb

Overview

User model conatining user create and update attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first_name: nil, last_name: nil, password: nil, current_password: nil, new_password: nil, date_of_birth: nil, email: nil, image_url: nil) ⇒ User

Inialise the User model

Parameters:

  • first_name (String) (defaults to: nil)
  • last_name (String) (defaults to: nil)
  • password (String) (defaults to: nil)
  • current_password (String) (defaults to: nil)
  • new_password (String) (defaults to: nil)
  • date_of_birth (String) (defaults to: nil)
  • email (String) (defaults to: nil)
  • image_url (String) (defaults to: nil)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/domain/user.rb', line 28

def initialize(first_name: nil, last_name: nil, password: nil,
               current_password: nil, new_password: nil,
               date_of_birth: nil, email: nil, image_url: nil)
  self.first_name = first_name
  self.last_name = last_name
  self.password = password
  self.current_password = current_password
  self.new_password = new_password
  self.date_of_birth = date_of_birth
  self.email = email
  self.image_url = image_url
end

Instance Attribute Details

#current_passwordObject

Returns the value of attribute current_password.



10
11
12
# File 'lib/domain/user.rb', line 10

def current_password
  @current_password
end

#date_of_birthObject

Returns the value of attribute date_of_birth.



12
13
14
# File 'lib/domain/user.rb', line 12

def date_of_birth
  @date_of_birth
end

#emailObject

Returns the value of attribute email.



13
14
15
# File 'lib/domain/user.rb', line 13

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



7
8
9
# File 'lib/domain/user.rb', line 7

def first_name
  @first_name
end

#image_urlObject

Returns the value of attribute image_url.



14
15
16
# File 'lib/domain/user.rb', line 14

def image_url
  @image_url
end

#last_nameObject

Returns the value of attribute last_name.



8
9
10
# File 'lib/domain/user.rb', line 8

def last_name
  @last_name
end

#new_passwordObject

Returns the value of attribute new_password.



11
12
13
# File 'lib/domain/user.rb', line 11

def new_password
  @new_password
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/domain/user.rb', line 9

def password
  @password
end

Class Method Details

.get_payload(user) ⇒ Json

Gets Json represenatation of user object

Parameters:

  • user (Object)

    User object

Returns:

  • (Json)

    Json represenatation of user object



73
74
75
# File 'lib/domain/user.rb', line 73

def self.get_payload(user)
  user.as_json.to_json
end

.get_payload_with_client_info(user) ⇒ Json

Gets Json represenatation of user object with client details

Parameters:

  • user (Object)

    User object

Returns:

  • (Json)

    Json represenatation of user object



84
85
86
# File 'lib/domain/user.rb', line 84

def self.get_payload_with_client_info(user)
  user.as_json.merge!({ 'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret }).to_json
end

Instance Method Details

#as_json(options = {}) ⇒ Hash

Converts User object to Hash and deletes null value fields

Parameters:

  • options (Refrence) (defaults to: {})

Returns:

  • (Hash)

    Hash of user object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/domain/user.rb', line 48

def as_json(options = {})
  hash_data = {
    self.class.name.downcase => {
      first_name: @first_name,
      last_name: @last_name,
      password: @password,
      current_password: @current_password,
      new_password: @new_password,
      date_of_birth: @date_of_birth,
      email: @email,
      image_url: @image_url
    }
  }

  hash_data.each { |k, v| v.delete_if { |k, v| v.nil? } }
  hash_data
end