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

Instance Method Details

#build_mentorship_group(mentorship_cycle:) ⇒ Object

Find or build



130
131
132
133
# File 'app/models/concerns/effective_mentorships_user.rb', line 130

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



142
143
144
145
# File 'app/models/concerns/effective_mentorships_user.rb', line 142

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



124
125
126
127
# File 'app/models/concerns/effective_mentorships_user.rb', line 124

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



136
137
138
139
# File 'app/models/concerns/effective_mentorships_user.rb', line 136

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_groupsObject



119
120
121
# File 'app/models/concerns/effective_mentorships_user.rb', line 119

def mentorship_registrations_without_groups
  mentorship_registrations.where.not(mentorship_cycle_id: mentorship_group_users.select(:mentorship_cycle_id))
end

#registrable_mentorship_cyclesObject

Used for the dashboard datatables. Which cycles can we register for?



113
114
115
116
117
# File 'app/models/concerns/effective_mentorships_user.rb', line 113

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