0.0
No commit activity in last 3 years
No release in over 3 years
Define an ability class for each of your models to separate authorizations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

ClassyCancan

Build Status

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.