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/contact.rb

48 lines
962 B
Ruby
Raw Normal View History

2019-08-10 20:23:12 -04:00
# frozen_string_literal: true
class Contact < ApplicationRecord
delegate :communicable?,
to: :contact_network,
allow_nil: true,
prefix: true
2019-08-10 20:23:12 -04:00
################
# Associations #
################
belongs_to :contact_list
belongs_to :contact_network
#############
# Callbacks #
#############
before_validation :turn_blanks_into_nils
before_validation :strip_extra_spaces
###############
# Validations #
###############
validates :contact_list, presence: true
validates :contact_network, presence: true
2019-09-04 13:01:14 -04:00
validates :value,
presence: true,
uniqueness: { scope: %i[contact_list_id contact_network_id] }
2019-08-10 20:23:12 -04:00
validates :send_security_notifications,
inclusion: { in: [false], unless: :contact_network_communicable? }
2019-08-10 20:23:12 -04:00
private
def turn_blanks_into_nils
self.value = nil if value.blank?
end
def strip_extra_spaces
self.value = value&.strip
end
end