Class: Permits::Ability
- Inherits:
-
Object
- Object
- Permits::Ability
- Includes:
- CanCan::Ability, Permit::Util
- Defined in:
- lib/cancan-permits/permits/ability.rb
Class Attribute Summary collapse
-
.orm ⇒ Object
Returns the value of attribute orm.
-
.strategy ⇒ Object
Returns the value of attribute strategy.
Class Method Summary collapse
-
.permits(ability, options = {}) ⇒ Object
set up each Permit instance to share this same Ability so that the can and cannot operations work on the same permission collection!.
Instance Method Summary collapse
-
#initialize(user, options = {}) ⇒ Ability
constructor
A new instance of Ability.
Methods included from Permit::Util
Constructor Details
#initialize(user, options = {}) ⇒ Ability
Returns a new instance of Ability.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cancan-permits/permits/ability.rb', line 39 def initialize user, = {} # put ability logic here! user ||= Guest.create all_permits = Permits::Ability.permits(self, ) all_permits.each do |permit| # get role name of permit permit_role = permit_name(permit.class) if permit_role == :system # always execute system permit result = permit.permit?(user, ) break if result == :break else # only execute the permit if the user has the role of the permit or is for any role if user.has_role?(permit_role) || permit_role == :any permit.permit?(user, ) end end end end |
Class Attribute Details
.orm ⇒ Object
Returns the value of attribute orm.
8 9 10 |
# File 'lib/cancan-permits/permits/ability.rb', line 8 def orm @orm end |
.strategy ⇒ Object
Returns the value of attribute strategy.
8 9 10 |
# File 'lib/cancan-permits/permits/ability.rb', line 8 def strategy @strategy end |
Class Method Details
.permits(ability, options = {}) ⇒ Object
set up each Permit instance to share this same Ability so that the can and cannot operations work on the same permission collection!
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cancan-permits/permits/ability.rb', line 23 def self.permits ability, = {} special_permits = [] special_permits << [:system, :any].map{|role| make_permit(role, ability, )} role_permits = Permits::Roles.available.inject([]) do |permits, role| permit = make_permit(role, ability, ) permits << permit if permit end # puts "Role permits: #{role_permits}" all_permits = (special_permits + role_permits).flatten.compact # # puts "All permits: #{all_permits}" # all_permits end |