Module: Troles::Common::Api::Read

Defined in:
lib/troles/common/api/read.rb

Instance Method Summary collapse

Instance Method Details

#has_any_role?(*roles) ⇒ Boolean

Checks if the role subject has any of the listed roles (see #has_roles?)

Returns:

  • (Boolean)


41
42
43
# File 'lib/troles/common/api/read.rb', line 41

def has_any_role? *roles
  !(role_list & roles.to_symbols).empty?
end

#has_role?(role) ⇒ true, false

Does the role subject has the role or not?

Returns:

  • (true, false)


21
22
23
# File 'lib/troles/common/api/read.rb', line 21

def has_role? role
  role_list.include? role.to_sym
end

#has_roles?(*roles) ⇒ true, false Also known as: has_all_roles?

Checks if the role subject has any of the listed roles

Parameters:

  • (Array<Symbol>)

Returns:

  • (true, false)


34
35
36
# File 'lib/troles/common/api/read.rb', line 34

def has_roles? *roles
  (roles.to_symbols - role_list).empty?
end

#is_role?(role) ⇒ true, false

Does the role subject have ONLY that role or not?

Returns:

  • (true, false)


27
28
29
# File 'lib/troles/common/api/read.rb', line 27

def is_role? role
  role_list.first == role.to_sym && role_list.size == 1
end

#role_listObject

Note:

This Set should be cached and only invalidated when the user has a change of roles

Ensures that the common API methods always have a common underlying model to work on



13
14
15
16
17
# File 'lib/troles/common/api/read.rb', line 13

def role_list        
  @role_list ||= begin
    store.display_roles.flatten
  end
end