Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
lib/generators/auth_assist/templates/ability.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, request) ⇒ Ability

Returns a new instance of Ability.



16
17
18
19
20
# File 'lib/generators/auth_assist/templates/ability.rb', line 16

def initialize(user, request)
  # put ability logic here!
  user ||= User.new # guest    
  Ability.role_permits.each{|rp| rp.permit?(user, request) }
end

Class Method Details

.role_permitsObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/generators/auth_assist/templates/ability.rb', line 4

def self.role_permits
  @role_permits if @role_permits

  # use inject ?
  @role_permits ||= [] 
  ['Admin', 'User', 'Author'].each do |role|                         
    # set up each RolePermit instance to share this same Ability so that the can and cannot operations work on the same permission collection!
    @role_permits << Kernel.const_get("RolePermit::#{role}").new(self)
  end
  @role_permits
end