Class: Course::GroupManagerPreloadService

Inherits:
Object
  • Object
show all
Defined in:
app/services/course/group_manager_preload_service.rb

Overview

Allows querying of group managers of users in a given collection without generating N+1 queries.

Instance Method Summary collapse

Constructor Details

#initialize(course_users) ⇒ GroupManagerPreloadService

Sets the collection of CourseUsers which group_managers_of will search from. Assumes that GroupUsers and their Groups have been loaded for each CourseUser.

Parameters:


9
10
11
# File 'app/services/course/group_manager_preload_service.rb', line 9

def initialize(course_users)
  @course_users = course_users
end

Instance Method Details

#group_managers_of(course_user) ⇒ Array<CourseUser>

Returns all managers of the groups that the given CourseUser are a part of. Assumes that GroupUsers and their Groups have been loaded for the given CourseUser.

Parameters:

  • course_user (CourseUser)

    The given CourseUser

Returns:


18
19
20
21
22
# File 'app/services/course/group_manager_preload_service.rb', line 18

def group_managers_of(course_user)
  course_user.groups.map do |group|
    group_managers_hash[group.id]
  end.flatten.compact.map(&:course_user).uniq
end

#no_group_managers?Boolean

Returns True if none of the given course users are group managers

Returns:

  • (Boolean)

    True if none of the given course users are group managers


25
26
27
# File 'app/services/course/group_manager_preload_service.rb', line 25

def no_group_managers?
  group_managers_hash.empty?
end