Classify your cancancan abilities
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.drone.yml
.gitignore
.rspec
.ruby-gemset
.ruby-version
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
classy_cancan.gemspec

README.md

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.