ClassyCancan
When using Cancan/can, a Ability
class in a larger Ruby on Rails application can grow quite quickly.
This gem lets you seperate model specific ability definitions into their own class.
This is a first approach to solve this. Pull Requests to make things easier to use are very much appreciated.
Installation
Add the following lines to your Gemfile
:
gem 'cancancan'
gem 'classy_cancan'
Now run bundle install
.
Note: This gem should work with both cancan and cancancan.
Usage
And this is how you use it:
# app/models/ability.rb
class Ability
include CanCan::Ability
def initialize(user)
ContactAbility.setup(self, user)
end
end
# app/models/abilities/contact_ability.rb
class ContactAbility < ClassyCancan::BaseAbility
def setup
can :manage, Contact
end
end
Todo
- Rails generator to create ability classes
Licence
This project rocks and uses MIT-LICENSE.