Sha256: d7bb0d28f816692e65bbec68c0652bb3b5489c5b4430b2ba12fd752c3fe4b4b3
Contents?: true
Size: 866 Bytes
Versions: 7
Compression:
Stored size: 866 Bytes
Contents
class Person < ApplicationRecord has_many :group_people, dependent: :destroy, autosave: true has_many :groups, through: :group_people, validate: true has_many :owned_groups, class_name: 'Group', foreign_key: 'owner_id', dependent: :nullify, autosave: true validates :first_name, presence: true, length: { in: 2..254 } validates :last_name, presence: true, length: { in: 2..254 } validates :gender, presence: true, length: { is: 1 }, inclusion: { in: %w(m f o), message: 'one of m (male), f (female), or o (other)' } validate :valid_date_of_birth? def valid_date_of_birth? return date_of_birth.nil? || (date_of_birth.is_a?(Date) && date_of_birth < Date.current) end private :valid_date_of_birth? def full_name(inversed: false) parts = [first_name, last_name] return inversed ? parts.reverse.join(', ') : parts.join(' ') end end
Version data entries
7 entries across 7 versions & 1 rubygems