Module: Shamu::Security::Roles

Extended by:
ActiveSupport::Concern
Included in:
Policy
Defined in:
lib/shamu/security/roles.rb

Overview

Mixin for Policy and Support classes to define security roles including inheritance.

Class Method Summary collapse

Class Method Details

.expand_roles(*roles) ⇒ Array<Symbol>

Expand the given roles to include the roles that they have inherited.

Parameters:

  • roles (Array<Symbol>)

Returns:

  • (Array<Symbol>)

    the expanded roles.



30
31
32
# File 'lib/shamu/security/roles.rb', line 30

def expand_roles( *roles )
  expand_roles_into( roles, Set.new ).to_a
end

.role(name, inherits: nil, scopes: nil)

This method returns an undefined value.

Define a named role.

Parameters:

  • name (Symbol)

    of the role.

  • inherits (Array<Symbol>) (defaults to: nil)

    additional roles that are automatically inherited when the named role is granted.

  • scopes (Array<Symbol>) (defaults to: nil)

    that the role may be granted in.



23
24
25
# File 'lib/shamu/security/roles.rb', line 23

def role( name, inherits: nil, scopes: nil )
  roles[ name.to_sym ] = { inherits: Array( inherits ), scopes: Array( scopes ) }
end

.role_defined?(role) ⇒ Boolean

Returns true if the role has been defined.

Parameters:

  • the (Symbol)

    role to check.

Returns:

  • (Boolean)

    true if the role has been defined.



36
37
38
# File 'lib/shamu/security/roles.rb', line 36

def role_defined?( role )
  roles.key?( role.to_sym )
end

.rolesHash

Returns the named roles defined on the class.

Returns:

  • (Hash)

    the named roles defined on the class.



12
13
14
# File 'lib/shamu/security/roles.rb', line 12

def roles
  @roles ||= {}
end