1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/person.rb

60 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2018-12-09 22:32:35 -05:00
# frozen_string_literal: true
class Person < ApplicationRecord
2019-03-26 16:40:53 -04:00
include Nameable
2019-09-01 10:42:16 -04:00
ACCOUNT_CONNECTION_TOKEN_RE = /\A\w+\z/.freeze
2019-03-25 20:56:31 -04:00
################
# Associations #
################
2019-08-28 12:59:39 -04:00
has_one_attached :photo
belongs_to :contact_list
2019-06-26 20:21:37 -04:00
has_one :account
2018-12-14 23:20:13 -05:00
has_many :all_relationships,
class_name: 'Relationship',
inverse_of: :person
2019-04-28 09:08:02 -04:00
has_many :person_comments
2019-07-15 17:19:11 -04:00
has_many :passports
2019-06-26 20:21:37 -04:00
###############
# Validations #
###############
validates :contact_list, uniqueness: true
2019-07-26 00:46:01 -04:00
2019-08-28 12:59:39 -04:00
validates :photo, allow_nil: true, image: true
2019-09-01 10:42:16 -04:00
validates :account_connection_token,
allow_nil: true,
allow_blank: false,
length: { is: 32 },
format: { with: ACCOUNT_CONNECTION_TOKEN_RE }
2019-07-26 00:46:01 -04:00
###########
# Methods #
###########
def full_name
[
last_name,
first_name,
middle_name,
].map(&:presence).compact.join(' ').freeze
end
def generate_account_connection_token
update! account_connection_token: SecureRandom.alphanumeric(32)
end
def destroy_account_connection_token
update! account_connection_token: nil
end
2018-12-09 22:32:35 -05:00
end