Class: UserProfile

Inherits:
ApplicationRecord show all
Extended by:
ActiveHash::Associations::ActiveRecordExtensions
Defined in:
app/models/user_profile.rb

Overview

This model is used to keep most of the information related to the user identity and role, in order to keep the User model as empty as possible. The User model only contains fields and associations that are strictly related to authentication.

Instance Attribute Summary collapse

Belongs to collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Attribute Details

#birthdayDate

Returns:

  • (Date)


233
# File 'db/schema.rb', line 233

t.date "birthday"

#blogString

Returns:

  • (String)


235
# File 'db/schema.rb', line 235

t.string "blog"

#country_codeString

Returns:

  • (String)


227
# File 'db/schema.rb', line 227

t.string "country_code"

#created_atDateTime

Returns:

  • (DateTime)


228
# File 'db/schema.rb', line 228

t.datetime "created_at"

#descriptionString

Returns:

  • (String)


231
# File 'db/schema.rb', line 231

t.string "description"

#full_nameString

Returns:

  • (String)


225
# File 'db/schema.rb', line 225

t.string "full_name"

#locationString

Returns:

  • (String)


232
# File 'db/schema.rb', line 232

t.string "location"

#passportString

Returns:

  • (String)


236
# File 'db/schema.rb', line 236

t.string "passport"

#phone_numberString

Returns:

  • (String)


226
# File 'db/schema.rb', line 226

t.string "phone_number"

#postal_addressString

Returns:

  • (String)


239
# File 'db/schema.rb', line 239

t.string "postal_address"

#role_idObject (readonly)



21
# File 'app/models/user_profile.rb', line 21

validates :role_id, presence: true

#second_phone_numberString

Returns:

  • (String)


230
# File 'db/schema.rb', line 230

t.string "second_phone_number"

#updated_atDateTime

Returns:

  • (DateTime)


229
# File 'db/schema.rb', line 229

t.datetime "updated_at"

#websiteString

Returns:

  • (String)


234
# File 'db/schema.rb', line 234

t.string "website"

#zip_codeString

Returns:

  • (String)


238
# File 'db/schema.rb', line 238

t.string "zip_code"

Class Method Details

.with_roleActiveRecord::Relation<UserProfile>

A relation of UserProfiles that are with role. Active Record Scope

Returns:

See Also:



25
26
27
28
29
30
31
# File 'app/models/user_profile.rb', line 25

scope :with_role, lambda { |role|
  if role.is_a?(UserRole)
    where(role_id: role.id)
  else
    where(role_id: UserRole.find_by_name(role.to_s).id)
  end
}

Instance Method Details

#missing_fieldsHash

List of fields that are required for processing reimbursements but are not present. The list of fields is set as a configuration parameter for the application.

Returns:

  • (Hash)

    hash with the name of the fields as keys and its human-readable names as values



43
44
45
46
47
# File 'app/models/user_profile.rb', line 43

def missing_fields
  fields = Rails.configuration.site['relevant_profile_fields']
  fields = fields.select { |f| send(f.to_sym).blank? }
  Hash[fields.map { |f| [f, self.class.human_attribute_name(f)] }]
end

#role_nameObject

Alias for Role#name

Returns:

  • (Object)

    Role#role_name

See Also:



19
# File 'app/models/user_profile.rb', line 19

delegate :name, to: :role, prefix: true, allow_nil: true

#set_default_attrsObject



33
34
35
# File 'app/models/user_profile.rb', line 33

def set_default_attrs
  self.role_name ||= 'none'
end

#userUser

The associated user (one to one association)

Returns:

See Also:



13
# File 'app/models/user_profile.rb', line 13

belongs_to :user