Class: Account

Inherits:
ApplicationRecord show all
Defined in:
app/models/account.rb

Overview

Account’s purpose is to correlate unique identifiers, and to remove our dependency on third party services for a user’s unique identifier.

The account.uuid is intended to become the Vets-API user’s uuid.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.lookup_by_user_account_uuid(user_uuid) ⇒ Object

Parameters:

  • user_uuid (String)

    The uuid of current_user in ApplicationController; refers to id for UserAccount table



62
63
64
65
66
67
# File 'app/models/account.rb', line 62

def self.(user_uuid)
   = UserAccount.find_by(id: user_uuid)
  return unless &.icn

  Account.where(icn: .icn).first
end

.lookup_by_user_uuid(user_uuid) ⇒ Object

Parameters:

  • user_uuid (String)

    The uuid of current_user in ApplicationController; may refer to the idme_uuid (preferred) or logingov_uuid



52
53
54
55
56
57
58
# File 'app/models/account.rb', line 52

def self.lookup_by_user_uuid(user_uuid)
  return if user_uuid.blank?

  Account.find_by(idme_uuid: user_uuid) ||
    Account.find_by(logingov_uuid: user_uuid) ||
    (user_uuid)
end

Instance Method Details

#generate_uuidObject (private)



81
82
83
# File 'app/models/account.rb', line 81

def generate_uuid
  SecureRandom.uuid
end

#initialize_uuidObject (private)



71
72
73
74
75
# File 'app/models/account.rb', line 71

def initialize_uuid
  new_uuid  = generate_uuid
  new_uuid  = generate_uuid until unique?(new_uuid)
  self.uuid = new_uuid
end

#unique?(new_uuid) ⇒ Boolean (private)

Returns:

  • (Boolean)


77
78
79
# File 'app/models/account.rb', line 77

def unique?(new_uuid)
  true unless Account.exists?(uuid: new_uuid)
end