sms-pager/app/models/person.rb

59 lines
1.3 KiB
Ruby
Raw Normal View History

2015-09-18 15:50:52 -05:00
class Person < ActiveRecord::Base
2015-10-07 22:03:31 -05:00
authenticates_with_sorcery!
2015-09-18 15:50:52 -05:00
has_many :parenthoods
has_many :children, through: :parenthoods
2015-10-07 22:03:31 -05:00
has_many :authentications, dependent: :destroy
accepts_nested_attributes_for :authentications
2015-10-03 08:04:16 -05:00
accepts_nested_attributes_for :children, reject_if: :all_blank
2015-09-18 15:50:52 -05:00
validates :first_name, presence: true
validates :last_name, presence: true
2015-10-03 08:04:16 -05:00
validates :phone, presence: true
2015-09-18 15:50:52 -05:00
scope :with_name, lambda { |name|
where("first_name || ' ' || last_name LIKE ?", "%#{name}%")
2015-09-18 15:50:52 -05:00
}
scope :just_parents, lambda {
joins(:children)
2015-10-03 19:16:46 -05:00
.order(:first_name, :last_name)
2015-09-18 15:50:52 -05:00
.uniq
}
2015-09-20 22:30:44 -05:00
scope :pageable, -> { where('phone is not NULL').order(:first_name) }
2015-09-18 15:50:52 -05:00
scope :staff, -> { where(staff: true) }
scope :admins, -> { where(admin: true) }
def name
"#{first_name} #{last_name}"
end
2015-10-03 15:15:19 -05:00
def to_i
id
end
2015-10-07 22:03:31 -05:00
def active?
activation_state == "active"
end
2015-10-23 19:57:32 -05:00
def active
activation_state == 'active'
end
def active=(bool)
if bool
self.activation_state = 'active'
else
self.ctivation_state = nil
end
end
2015-10-07 22:03:31 -05:00
private
## SorceryCore expects the model to hold a crypted_password field
## Since we are only using external oAuth providers, faking this one out.
def crypted_password; end
2015-09-18 15:50:52 -05:00
end