Module: EffectiveMentorshipsUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_mentorships_user.rb
Overview
EffectiveMentorshipsUser
Mark your user model with effective_mentorship_user to get a few helpers And user specific point required scores
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#build_mentorship_group(mentorship_cycle:) ⇒ Object
Find or build.
-
#build_mentorship_registration(mentorship_cycle:) ⇒ Object
Find or build.
-
#mentorship_group(mentorship_cycle:) ⇒ Object
Find.
-
#mentorship_registration(mentorship_cycle:) ⇒ Object
Find.
- #mentorship_registrations_without_groups ⇒ Object
-
#registrable_mentorship_cycles ⇒ Object
Used for the dashboard datatables.
Instance Method Details
#build_mentorship_group(mentorship_cycle:) ⇒ Object
Find or build
50 51 52 53 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 50 def build_mentorship_group(mentorship_cycle:) raise('expected an MentorshipCycle') unless mentorship_cycle.class.respond_to?(:effective_mentorships_cycle?) mentorship_group(mentorship_cycle: mentorship_cycle) || mentorship_groups.build(mentorship_cycle: mentorship_cycle) end |
#build_mentorship_registration(mentorship_cycle:) ⇒ Object
Find or build
62 63 64 65 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 62 def build_mentorship_registration(mentorship_cycle:) raise('expected an MentorshipCycle') unless mentorship_cycle.class.respond_to?(:effective_mentorships_cycle?) mentorship_registration(mentorship_cycle: mentorship_cycle) || mentorship_registrations.build(mentorship_cycle: mentorship_cycle) end |
#mentorship_group(mentorship_cycle:) ⇒ Object
Find
44 45 46 47 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 44 def mentorship_group(mentorship_cycle:) raise('expected an MentorshipCycle') unless mentorship_cycle.class.respond_to?(:effective_mentorships_cycle?) mentorship_groups.find { |mentorship_group| mentorship_group.mentorship_cycle_id == mentorship_cycle.id } end |
#mentorship_registration(mentorship_cycle:) ⇒ Object
Find
56 57 58 59 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 56 def mentorship_registration(mentorship_cycle:) raise('expected an MentorshipCycle') unless mentorship_cycle.class.respond_to?(:effective_mentorships_cycle?) mentorship_registrations.find { |mentorship_registration| mentorship_registration.mentorship_cycle_id == mentorship_cycle.id } end |
#mentorship_registrations_without_groups ⇒ Object
39 40 41 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 39 def mentorship_registrations_without_groups mentorship_registrations.where.not(mentorship_cycle_id: mentorship_group_users.select(:mentorship_cycle_id)) end |
#registrable_mentorship_cycles ⇒ Object
Used for the dashboard datatables. Which cycles can we register for?
33 34 35 36 37 |
# File 'app/models/concerns/effective_mentorships_user.rb', line 33 def registrable_mentorship_cycles Effective::MentorshipCycle.registrable .where.not(id: mentorship_group_users.select(:mentorship_cycle_id)) .where.not(id: mentorship_registrations.select(:mentorship_cycle_id)) end |