Sha256: f56295f6d783d0ea8afb8065da58a32aa453201b01cf0646dd3616aff84c69e2

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

class Persona::Individual < Persona::Model
  extend EnumerateIt

  self.abstract_class = true

  mount_uploader :image, IndividualImageUploader

  has_enumeration_for :gender, create_helpers: true
  has_enumeration_for :marital_status
  has_enumeration_for :nationality

  has_paper_trail

  belongs_to :place_of_birth, class_name: '::City'
  belongs_to :country_of_birth, class_name: '::Country'

  has_one :identity, class_name: '::Identity', dependent: :destroy
  has_one :person, as: :personable, class_name: '::Person'

  accepts_nested_attributes_for :identity, reject_if: :all_blank

  validates :gender, presence: true
  validates :cpf, cpf: true, mask: '999.999.999-99', allow_blank: true, if: :cpf_is_not_zeros?
  validates :cpf, uniqueness: { if: :validate_cpf_uniqueness? }, allow_blank: true, if: :cpf_is_not_zeros?
  validates :birthdate, timeliness: { before: :today, type: :date }, allow_blank: true

  def to_s
    person.name
  end

  protected

  def validate_cpf_uniqueness?
    true
  end

  def cpf_is_not_zeros?
    cpf != '000.000.000-00'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unico-training-7.8.0 app/models/persona/individual.rb