Module: EffectiveMentorshipsGroup
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_mentorships_group.rb
Overview
EffectiveMentorshipsGroup
Mark your group model with effective_mentorships_group to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #assign_title ⇒ Object
-
#build_mentee(user:) ⇒ Object
Find or build.
-
#build_mentor(user:) ⇒ Object
Find or build.
-
#build_mentorship_group_user(user:, mentorship_role:) ⇒ Object
Find or build.
- #mentees ⇒ Object
- #mentors ⇒ Object
-
#mentorship_group_user(user:) ⇒ Object
Find.
- #notify! ⇒ Object
- #present_mentorship_group_users ⇒ Object
-
#to_s ⇒ Object
Instance Methods.
Instance Method Details
#assign_title ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 75 def assign_title if present_mentorship_group_users.blank? assign_attributes(title: "Empty") else mentor_names = mentors.map { |user| user.try(:first_name) || user.to_s.split(' ').first }.sort mentee_names = mentees.map { |user| user.try(:first_name) || user.to_s.split(' ').first }.sort assign_attributes(title: (mentor_names + mentee_names).join(', ')) end end |
#build_mentee(user:) ⇒ Object
Find or build
118 119 120 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 118 def build_mentee(user:) build_mentorship_group_user(user: user, mentorship_role: :mentee) end |
#build_mentor(user:) ⇒ Object
Find or build
113 114 115 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 113 def build_mentor(user:) build_mentorship_group_user(user: user, mentorship_role: :mentor) end |
#build_mentorship_group_user(user:, mentorship_role:) ⇒ Object
Find or build
107 108 109 110 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 107 def build_mentorship_group_user(user:, mentorship_role:) raise("unexpected mentorship role: #{mentorship_role}") unless EffectiveMentorships.MentorshipRegistration.mentorship_roles.include?(mentorship_role) mentorship_group_user(user: user) || mentorship_group_users.build(user: user, mentorship_role: mentorship_role) end |
#mentees ⇒ Object
130 131 132 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 130 def mentees present_mentorship_group_users.select(&:mentee?).map(&:user) end |
#mentors ⇒ Object
126 127 128 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 126 def mentors present_mentorship_group_users.select(&:mentor?).map(&:user) end |
#mentorship_group_user(user:) ⇒ Object
Find
102 103 104 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 102 def mentorship_group_user(user:) mentorship_group_users.find { |mgu| mgu.user == user } end |
#notify! ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 86 def notify! return false unless published? present_mentorship_group_users.each do |mentorship_group_user| case mentorship_group_user.mentorship_role.to_s when 'mentor' EffectiveMentorships.send_email(:mentorship_group_created_to_mentor, mentorship_group_user) when 'mentee' EffectiveMentorships.send_email(:mentorship_group_created_to_mentee, mentorship_group_user) end end update!(last_notified_at: Time.zone.now) end |
#present_mentorship_group_users ⇒ Object
122 123 124 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 122 def present_mentorship_group_users mentorship_group_users.reject(&:marked_for_destruction?) end |
#to_s ⇒ Object
Instance Methods
71 72 73 |
# File 'app/models/concerns/effective_mentorships_group.rb', line 71 def to_s title.presence || model_name.human end |