class Permisi::Backend::ActiveRecord::Actor

Public Instance Methods

aggregate_permissions() click to toggle source

Aggregate permissions from all roles an actor plays

# File lib/permisi/backend/active_record/actor.rb, line 31
def aggregate_permissions
  roles.load.inject(HashWithIndifferentAccess.new) do |aggregate, role|
    aggregate.deep_merge(role.permissions) do |_key, effect, another_effect|
      effect == true || another_effect == true
    end
  end
end
has_role?(role_slug)
Alias for: role?
may?(action_path)
Alias for: may_i?
may_i?(action_path) click to toggle source
# File lib/permisi/backend/active_record/actor.rb, line 21
def may_i?(action_path)
  PermissionUtil.allows?(permissions, action_path)
end
Also aliased as: may?
permissions() click to toggle source

Memoized and cached actor permissions

# File lib/permisi/backend/active_record/actor.rb, line 26
def permissions
  @permissions ||= Permisi.config.cache_store.fetch("#{cache_key}-p") { aggregate_permissions }
end
reset_permissions() click to toggle source
# File lib/permisi/backend/active_record/actor.rb, line 39
def reset_permissions
  @permissions = nil
end
role?(role_slug) click to toggle source
# File lib/permisi/backend/active_record/actor.rb, line 17
def role?(role_slug)
  roles.load.any? { |role| role.slug == role_slug.to_s }
end
Also aliased as: has_role?
roles() click to toggle source
Calls superclass method
# File lib/permisi/backend/active_record/actor.rb, line 13
def roles
  super.extend(ActorRolesCollectionProxy)
end