UNMAINTAINED Agnostic roles for Rails!
Ruby JavaScript
Switch branches/tags
Latest commit 4dcebfc Oct 15, 2013 @timonv Update README.textile
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
LICENCE
README.textile
Rakefile
rollable.gemspec

README.textile

Rollable is a very old gem that should not be used in production. It is unmaintained and untested with Rails > 2.3. Also, the code is very crude and dodgy.

Rollable

Rollable is a Rails gem that adds agnostic roles to your application. The core principle is that a role should not
be coupled to any object, but is nothing more than a relationship. Rollable does not define semantics, you can use
cancan or some similar gem to do just that.

Installation

Add to your gemfile

gem ‘rollable’

And run

bundle install

Setup

Rollable is ment to be easy and maintainable, with a minimal amount of configuration nescecary.

Setup the role model and migration, where is the model name you want to be able to have roles

rails generate rollable:setup
rake db:migrate

Configuration

Just two lines!

In the model you defined during setup:

include Rollable::Base
rollables model names, option hash

Currently, the available options are:

:roles => [Array of Strings] # Role names
:allow_nil => false # If true, you can create generic roles (like ‘admin’)

Features

  • Hardly any configuration
  • Validates role names, role types by inclusion and user presence on Role (all dynamic)
  • Much more!

Usage

We’ll call the model that can have roles users, for the sake of laziness.

Rollable provides helpers based on role names to check whether a user has a role on an object:

user.is_owner_of?(horse) # => true

You can also request all possible roles

User.role_names

You can set roles easily by using the helper

user.is_owner(horse)

If you use nil roles, you can also do

user.is_admin?

Since 0.0.2 you can also do

target_model.has_admin?

And, to get all users with that role

target_model.get_admins

Limitations

  • Its the first release, don’t whine.
  • Role names can only be single words (so no underscores), but keep it simple, right?

Questions? Comments? Contribute? All welcome!

- Timon Vonk