RoleMe

Adds simple role handling to model.

How to use

Supose you have an User model:

class User < ActiveRecord::Base
  include RoleMe::HasRoles
  has_roles
end

Then, you have:

user = User.first
user.has_role! :admin     # adds the admin role to the model
user.has_role? :admin     # checks if the model has the admin role

Installation

Add to your `Gemfile`:

gem 'role_me'

And use the role_me:role_migration generator to create the role migration, if you are using the gem's role model.

rails generator role_me:role_migration

Custom Role Model

If you want to use a custom model for Roles, please make sure that:

  • It has a `with_name(role_name)` scope. This must filter the roles by their names.

  • It responds to `find_or_create_by_name(role_name)`.

has_roles Options

  • :role_class_name

    “RoleMe::Role” by default. You can use you own role model, just pass it through here.

  • :role_join_table

    This is the name of the join table between the roled and the role model. By default “role_me_roles_join”.