Bitroleable
Manage user roles. Each user's role is stored as a bit in an integer
column of database. Also provides user ability to have one role and
some roles.
Installation
Add this line to your application's Gemfile:
gem 'bitroleable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bitroleable
Usage
Add a column which will store role/roles as integer:
add_column :user, :roles, :integer, null: false
And then tell a model that you use this gem functionality:
class User < ActiveRecord::Base
roleable :roles, [:user, :moderator, :admin], multi: true
end
Options
For now it has only one option:
multi
(boolean) - when it equals true
an entity could have many roles, otherwise only one role
Example
user = User.first
user.admin!
user.admin?
user.role?(:admin)
user.user?
user.role
user.role = [:user, :moderator]
user.role
user.save!
User.where_role(:admin).count
User.where_role(:user).count
User.where_role(:moderator).count
User.roles_list
User.role?(:user)
User.role?(:fake)
Contributing
- Fork it ( https://github.com/ekondr/bitroleable/fork )
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create a new Pull Request