Module: Cancannible::Grantee
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cancannible/grantee.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#abilities(refresh = false) ⇒ Object
Returns the Ability set for the owner.
-
#can(ability, resource) ⇒ Object
Command: grant the permission to do
ability
onresource
. -
#can?(ability, resource) ⇒ Boolean
Returns true it the
ability
is permitted onresource
- persisted or dynamic (delegated to CanCan). -
#cannot(ability, resource) ⇒ Object
Command: prohibit the permission to do
ability
onresource
. -
#cannot?(ability, resource) ⇒ Boolean
Returns true it the
ability
is prohibited onresource
- persisted or dynamic (delegated to CanCan). -
#inherited_permissions ⇒ Object
Returns the collection of inherited permission records.
Instance Method Details
#abilities(refresh = false) ⇒ Object
Returns the Ability set for the owner. Set refresh
to true to force a reload of permissions.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cancannible/grantee.rb', line 58 def abilities(refresh = false) @abilities = if refresh nil elsif Cancannible.get_cached_abilities.respond_to?(:call) Cancannible.get_cached_abilities.call(self) end return @abilities if @abilities @abilities ||= if ability_class = ('Ability'.constantize rescue nil) unless ability_class.included_modules.include?(Cancannible::PreloadAdapter) ability_class.send :include, Cancannible::PreloadAdapter end ability_class.new(self) end Cancannible.store_cached_abilities.call(self,@abilities) if Cancannible.store_cached_abilities.respond_to?(:call) @abilities end |
#can(ability, resource) ⇒ Object
Command: grant the permission to do ability
on resource
99 100 101 |
# File 'lib/cancannible/grantee.rb', line 99 def can(ability, resource) << [ability, resource] end |
#can?(ability, resource) ⇒ Boolean
Returns true it the ability
is permitted on resource
- persisted or dynamic (delegated to CanCan)
89 90 91 |
# File 'lib/cancannible/grantee.rb', line 89 def can?(ability, resource) abilities.can?(ability, resource) end |
#cannot(ability, resource) ⇒ Object
Command: prohibit the permission to do ability
on resource
104 105 106 |
# File 'lib/cancannible/grantee.rb', line 104 def cannot(ability, resource) << [ability, resource, false] end |
#cannot?(ability, resource) ⇒ Boolean
Returns true it the ability
is prohibited on resource
- persisted or dynamic (delegated to CanCan)
94 95 96 |
# File 'lib/cancannible/grantee.rb', line 94 def cannot?(ability, resource) abilities.cannot?(ability, resource) end |
#inherited_permissions ⇒ Object
Returns the collection of inherited permission records
78 79 80 81 82 83 84 85 86 |
# File 'lib/cancannible/grantee.rb', line 78 def inherited_perms = [] self.class..each do |relation| Array(self.send(relation)).each do |record| inherited_perms.concat(record..reload) end end inherited_perms end |