Class: Course::CourseOwnerPreloadService

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

Instance Method Summary collapse

Constructor Details

#initialize(course_ids) ⇒ Hash{course_id => Array<CourseUser>}

Preloads course owners for a collection of courses.

Parameters:

  • course_ids (Array<Integer>)

8
9
10
# File 'app/services/course/course_owner_preload_service.rb', line 8

def initialize(course_ids)
  @owners = CourseUser.owner.includes(:user).where(course_id: course_ids).group_by(&:course_id)
end

Instance Method Details

#course_owners_for(course_id) ⇒ Array<CourseUser>|nil

Finds the course owners for the given course.

Parameters:

  • course_id (Integer)

Returns:

  • (Array<CourseUser>|nil)

    The course owners, if found, else nil


16
17
18
# File 'app/services/course/course_owner_preload_service.rb', line 16

def course_owners_for(course_id)
  @owners[course_id]
end