Very basic and simple roles system for mongoid v3. HEAVILY INSPIRED by mongoid-simple-tags
Install
Add the following to Gemfile:
gem "mongoid-simple-roles", "0.0.1"
Usage
Model
class User
include Mongoid::Document
include Mongoid::Document::Roleable
end
Console
u = User.create(:name => "Drefined", with_roles: ['superadmin', 'admin', 'user'])
u.roles
=> ['superadmin', 'admin', 'user']
User.find_roles('superadmin')
=> u
u2 = User.new(:name => "Quicksorter")
u2.add_role('admin')
u2.add_role('user')
u2.save
u2.has_role?('admin')
=> true
u2.remove_role('user')
u2.has_role?('user')
=> false
User.find_roles('admin')
=> [u, u2]
Questions or Problems?
If you have any issue or feature request with/for mongoid-simple-roles, please add an issue on GitHub or fork the project and send a pull request.