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



31
32
33
# File 'app/models/gaku/contact.rb', line 31

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

.primaryObject



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

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

.primary_emailObject



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

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

.secondaryObject



52
53
54
# File 'app/models/gaku/contact.rb', line 52

def self.secondary
  where(primary: false)
end

.studentsObject



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

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

.teachersObject



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

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

Instance Method Details

#make_primaryObject



35
36
37
38
39
40
41
42
# File 'app/models/gaku/contact.rb', line 35

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

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

#primary?Boolean

Returns:

  • (Boolean)


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

def primary?
  primary
end

#to_sObject



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

def to_s
  data
end