Project

bitroles

0.0
No commit activity in last 3 years
No release in over 3 years
Simple roles for your models without external tables
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

Bitroles

Simple roles for your models without external tables

Installation

Add this line to your application's Gemfile:

gem 'bitroles'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bitroles

Usage

class MyModel < ActiveRecord::Base
  has_roles :admin, :moderator
end

By default bitroles uses roles_mask integer column in your table to store the roles. You can change column name pretty easy:

class MyModel < ActiveRecord::Base
  has_roles :admin, :moderator, mask_column: :someothercolumn
end

Available methods

objects = MyModel.with_role(:admin) # Finds all MyModel objects with admin role
obj = objects.first
obj.has_role? :admin # Checks if the object has admin role
obj.is_admin? # Checks the above. It can be is_moderator? or is_whatever? depends on roles given to has_role
obj.roles # Shows all roles of object (strings array)
obj.roles = [:admin, :moderator] # Sets admin and moderator role to obj
obj.admin = true # obj became admin (same for other roles)
obj.admin = false # obj is no longer an admin (same for other roles)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request