Class: Permisi::Backend::ActiveRecord::Actor
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Permisi::Backend::ActiveRecord::Actor
show all
- Defined in:
- lib/permisi/backend/active_record/actor.rb
Defined Under Namespace
Modules: ActorRolesCollectionProxy
Instance Method Summary
collapse
Instance Method Details
#aggregate_permissions ⇒ Object
Aggregate permissions from all roles an actor plays
31
32
33
34
35
36
37
|
# 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
|
#may_i?(action_path) ⇒ Boolean
Also known as:
may?
21
22
23
|
# File 'lib/permisi/backend/active_record/actor.rb', line 21
def may_i?(action_path)
PermissionUtil.allows?(permissions, action_path)
end
|
#permissions ⇒ Object
Memoized and cached actor permissions
26
27
28
|
# 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 ⇒ Object
39
40
41
|
# File 'lib/permisi/backend/active_record/actor.rb', line 39
def reset_permissions
@permissions = nil
end
|
#role?(role_slug) ⇒ Boolean
Also known as:
has_role?
17
18
19
|
# 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
|