module Troles::Common::Api::Read

Public Instance Methods

has_all_roles?(*roles)
Alias for: has_roles?
has_any_role?(*roles) click to toggle source

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

# File lib/troles/common/api/read.rb, line 41
def has_any_role? *roles
  !(role_list & roles.to_symbols).empty?
end
has_role?(role) click to toggle source

Does the role subject has the role or not? @return [true, false]

# File lib/troles/common/api/read.rb, line 21
def has_role? role
  role_list.include? role.to_sym
end
has_roles?(*roles) click to toggle source

Checks if the role subject has any of the listed roles @param [Array<Symbol>] @return [true, false]

# File lib/troles/common/api/read.rb, line 34
def has_roles? *roles
  (roles.to_symbols - role_list).empty?
end
Also aliased as: has_all_roles?
is_role?(role) click to toggle source

Does the role subject have ONLY that role or not? @return [true, false]

# 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_list() click to toggle source

Ensures that the common API methods always have a common underlying model to work on @note This Set should be cached and only invalidated when the user has a change of roles

@return Array<Symbol> Set of role names

# File lib/troles/common/api/read.rb, line 13
def role_list        
  @role_list ||= begin
    store.display_roles.flatten
  end
end