Module: AbilityHost::CourseHelpers

Defined in:
app/models/components/ability_host.rb

Overview

Helpers for defining abilities associated with a course user.

Instance Method Summary collapse

Instance Method Details

#course_course_user_hash(*roles) ⇒ Hash (protected) Also known as: course_all_course_users_hash

Returns Hash is relative to a component with a +belongs_to+ association with a Course.

Returns:

  • (Hash)

    Hash is relative to a component with a +belongs_to+ association with a Course.


37
38
39
# File 'app/models/components/ability_host.rb', line 37

def course_course_user_hash(*roles)
  { course: course_user_hash(*roles) }
end

#course_managers_hashHash (protected)

Returns Hash is relative to a component with a +belongs_to+ association with a Course.

Returns:

  • (Hash)

    Hash is relative to a component with a +belongs_to+ association with a Course.


54
55
56
# File 'app/models/components/ability_host.rb', line 54

def course_managers_hash
  course_course_user_hash(*CourseUser::MANAGER_ROLES.to_a)
end

#course_staff_hashHash (protected)

Returns Hash is relative to a component with a +belongs_to+ association with a Course.

Returns:

  • (Hash)

    Hash is relative to a component with a +belongs_to+ association with a Course.


44
45
46
# File 'app/models/components/ability_host.rb', line 44

def course_staff_hash
  course_course_user_hash(*CourseUser::STAFF_ROLES.to_a)
end

#course_teaching_staff_hashHash (protected)

Returns Hash is relative to a component with a +belongs_to+ association with a Course.

Returns:

  • (Hash)

    Hash is relative to a component with a +belongs_to+ association with a Course.


49
50
51
# File 'app/models/components/ability_host.rb', line 49

def course_teaching_staff_hash
  course_course_user_hash(*CourseUser::TEACHING_STAFF_ROLES.to_a)
end

#course_user_hash(*roles) ⇒ Hash (protected)

Creates a hash which allows referencing a set of course users.

Parameters:

  • roles (Array<Symbol>)

    The roles CourseUser::Roles which should be referenced by this rule.

Returns:

  • (Hash)

    This hash is relative to a Course.


14
15
16
17
18
19
# File 'app/models/components/ability_host.rb', line 14

def course_user_hash(*roles)
  course_users = { user_id: user.id }
  course_users[:role] = roles.map { |role| CourseUser.roles[role] } unless roles.empty?

  { course_users: course_users }
end

#managers_hashHash (protected)

Returns Hash relative to a component with a +has_many+ association with CourseUser.

Returns:

  • (Hash)

    Hash relative to a component with a +has_many+ association with CourseUser.


32
33
34
# File 'app/models/components/ability_host.rb', line 32

def managers_hash
  course_user_hash(*CourseUser::MANAGER_ROLES.to_a)
end

#staff_hashHash (protected)

Returns Hash relative to a component with a +has_many+ association with CourseUser.

Returns:

  • (Hash)

    Hash relative to a component with a +has_many+ association with CourseUser.


22
23
24
# File 'app/models/components/ability_host.rb', line 22

def staff_hash
  course_user_hash(*CourseUser::STAFF_ROLES.to_a)
end

#teaching_staff_hashHash (protected)

Returns Hash relative to a component with a +has_many+ association with CourseUser.

Returns:

  • (Hash)

    Hash relative to a component with a +has_many+ association with CourseUser.


27
28
29
# File 'app/models/components/ability_host.rb', line 27

def teaching_staff_hash
  course_user_hash(*CourseUser::TEACHING_STAFF_ROLES.to_a)
end