Sha256: e8abf68bac7e833930c9a7b5f9041d6dea87e4c4736650e524665d820a0ef605

Contents?: true

Size: 851 Bytes

Versions: 7

Compression:

Stored size: 851 Bytes

Contents

class Person < ActiveRecord::Base
  has_many :group_people, dependent: :destroy, autosave: true
  has_many :groups, through: :group_people
  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

Version Path
kadmin-0.3.1 test/dummy/app/models/person.rb
kadmin-0.3.0 test/dummy/app/models/person.rb
kadmin-0.2.8 test/dummy/app/models/person.rb
kadmin-0.2.7 test/dummy/app/models/person.rb
kadmin-0.2.6 test/dummy/app/models/person.rb
kadmin-0.2.3 test/dummy/app/models/person.rb
kadmin-0.2.2 test/dummy/app/models/person.rb