Class: LTIRoles::RoleManager

Inherits:
Object
  • Object
show all
Defined in:
lib/lti_roles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(roles = '') ⇒ RoleManager

Returns a new instance of RoleManager.



13
14
15
16
17
18
19
# File 'lib/lti_roles.rb', line 13

def initialize(roles = '')
  @roles = roles
  @context_types = map_roles(ContextTypeURN)
  @system_roles = map_roles(SystemRoleURN)
  @institution_roles = map_roles(InstitutionRoleURN)
  @context_roles = map_roles(ContextRoleURN)
end

Instance Attribute Details

#context_rolesObject

Returns the value of attribute context_roles.



11
12
13
# File 'lib/lti_roles.rb', line 11

def context_roles
  @context_roles
end

#context_typesObject

Returns the value of attribute context_types.



11
12
13
# File 'lib/lti_roles.rb', line 11

def context_types
  @context_types
end

#institution_rolesObject

Returns the value of attribute institution_roles.



11
12
13
# File 'lib/lti_roles.rb', line 11

def institution_roles
  @institution_roles
end

#rolesObject

Returns the value of attribute roles.



11
12
13
# File 'lib/lti_roles.rb', line 11

def roles
  @roles
end

#system_rolesObject

Returns the value of attribute system_roles.



11
12
13
# File 'lib/lti_roles.rb', line 11

def system_roles
  @system_roles
end

Instance Method Details

#map_roles(urn_prefix) ⇒ Object



21
22
23
24
25
26
# File 'lib/lti_roles.rb', line 21

def map_roles(urn_prefix)
  roles.split(',').map do |role|
    next unless role.include?(urn_prefix)
    role.gsub(urn_prefix, '').gsub('/', '').underscore
  end.compact
end

#to_hObject



28
29
30
31
32
33
34
35
36
# File 'lib/lti_roles.rb', line 28

def to_h
  {
    'roles' => roles,
    'context_type' => context_types,
    'system_roles' => system_roles,
    'institution_roles' => institution_roles,
    'context_roles' => context_roles
  }
end