Class: Gaku::Contact

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gaku/contact.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.guardiansObject



26
27
28
# File 'app/models/gaku/contact.rb', line 26

def self.guardians
  where(contactable_type: Gaku::Guardian)
end

.primaryObject



43
44
45
# File 'app/models/gaku/contact.rb', line 43

def self.primary
  where(primary: true).first
end

.primary_emailObject



14
15
16
# File 'app/models/gaku/contact.rb', line 14

def self.primary_email
  where(primary: true, contact_type: Gaku::ContactType.where(name: 'Email').first).first
end

.secondaryObject



47
48
49
# File 'app/models/gaku/contact.rb', line 47

def self.secondary
  where(primary: false)
end

.studentsObject



18
19
20
# File 'app/models/gaku/contact.rb', line 18

def self.students
  where(contactable_type: Gaku::Student)
end

.teachersObject



22
23
24
# File 'app/models/gaku/contact.rb', line 22

def self.teachers
  where(contactable_type: Gaku::Teacher)
end

Instance Method Details

#make_primaryObject



30
31
32
33
34
35
36
37
# File 'app/models/gaku/contact.rb', line 30

def make_primary
  contactable.contacts.where.not(id: id).update_all(primary: false)
  update_attribute(:primary, true)

  # if contactable.has_attribute?(:primary_contact)
  #   contactable.update_attribute(:primary_contact, contactable.contact_widget)
  # end
end

#primary?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/gaku/contact.rb', line 39

def primary?
  primary
end

#to_sObject



10
11
12
# File 'app/models/gaku/contact.rb', line 10

def to_s
  data
end