0.0
No commit activity in last 3 years
No release in over 3 years
Mongoid Roles
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 2.0.0.rc.7
>= 0
 Project Readme

Mongoid Roles

Role-based authorization system for Rails & Mongoid.

Interface is based on acl9.

Installation

Add this line to your Gemfile:

gem 'mongoid_roles'

Subject model


  class User
    include Mongoid::Document
    include Mongoid::Roles::Subject
  end

Object model


    class Foo
      include Mongoid::Document
      include Mongoid::Roles::Object
    end
    
    class Bar
      include Mongoid::Document
      include Mongoid::Roles::Object
    end

Interface

Subject model

A call of include Mongoid::Roles::Subject defines following methods on the model:

subject.has_role?(role, object = nil). Returns true of false (has or has not).

subject.has_role!(role, object = nil). Assigns a role for the object to the subject.
Does nothing is subject already has such a role.

subject.has_no_role!(role, object = nil). Unassigns a role from the subject.

subject.has_roles_for?(object). Does the subject has any roles for object? (true of false)

subject.has_role_for?(object). Same as has_roles_for?.

subject.roles_for(object). Returns an array of Role instances, corresponding to subject ’s roles on
object. E.g. subject.roles_for(object).map(&:name).sort will give you role names in alphabetical order.

subject.has_no_roles_for!(object). Unassign any subject ’s roles for a given object.

subject.has_no_roles!. Unassign all roles from subject.

Object model

A call of include Mongoid::Roles::Object defines following methods on the model:

object.accepts_role?(role_name, subject). An alias for subject.has_role?(role_name, object).

object.accepts_role!(role_name, subject). An alias for subject.has_role!(role_name, object).

object.accepts_no_role!(role_name, subject). An alias for subject.has_no_role!(role_name, object).

object.accepts_roles_by?(subject). An alias for subject.has_roles_for?(object).

object.accepts_role_by?(subject). Same as accepts_roles_by?.

object.accepts_roles_by(subject). An alias for subject.roles_for(object).