module Authz::Models::Rolable

Must be included in the host application's class in charge of users.

Public Instance Methods

authorizable_association_name() click to toggle source

Returns a handle to the name (symbol) of the association method that points from other classes to this Authorizable

# File lib/authz/models/rolable.rb, line 82
def authorizable_association_name
  model_name.plural.to_sym
end
authz_label() click to toggle source

@return [String] Label used to label each rolable instance in the context

of Authz
# File lib/authz/models/rolable.rb, line 47
def authz_label
  if respond_to? :name
    name
  elsif respond_to? :email
    email
  elsif respond_to? :id
    "#{self.to_s}##{id}"
  else
    to_s
  end
end
authz_label_method(method_name) click to toggle source

Developers can use this to specify which method form the includer should be used inside authz to label each instance

# File lib/authz/models/rolable.rb, line 74
def authz_label_method method_name
  define_method 'authz_label' do
    self.send(method_name)
  end
end
roles_cache_key() click to toggle source

@return [String] a composite cache key using the keys of the granted roles.

The key will be modified when the configuration of any of the granted
roles changes.
# File lib/authz/models/rolable.rb, line 62
def roles_cache_key
  roles.map(&:cache_key).join('/')
end