Class: Kaui::Ability
- Inherits:
-
Object
- Object
- Kaui::Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/kaui/ability.rb
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user) ⇒ Ability
Returns a new instance of Ability.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/kaui/ability.rb', line 5 def initialize(user) # user is a Kaui::User object (from Devise) user..each do || # permission is something like invoice:item_adjust or payment:refund # We rely on a naming convention where the left part refers to a Kaui model model, action = .split(':') if model == '*' and action == '*' # All permissions! can :manage, :all elsif model == '*' and action != '*' # TODO elsif action == '*' can :all, ('Kaui::' + model.capitalize).constantize rescue nil else can action.to_sym, ('Kaui::' + model.capitalize).constantize rescue nil end end rescue KillBillClient::API::Unauthorized => e end |