Generic role model strategies sharing same API easy to insert in any model
MIT License
h1. Generic Roles
Generic Roles (or simply Roles) is a generic Roles API implementation that specific ORM Roles implementations can implement. This way you can easily change ORM and still keep using the same underlying API.
A Rails 3 generator is included that can configure an existing User model with a generic Role strategy of choice. Each ORM Roles implementation should have its own generator suited for that particular ORM.
Since Jan. 2011, Roles now includes a Group API that allows ordering roles into groups (see below).
h2. You need help?
Please post questions in the "rails-roles":http://groups.google.com/group/rails-roles group. If you have issues or bug reports, please post these as Issues on the github. I recommend you try to fix any problems you might encounter by forking the project, implement the fix by writing specs and make a pull request to integrate it into my master. Thanks!
h2. Roles ORM implementations
The following ORM specific Roles implementations are currently available
h3. Relational Database (SQL)
h3. Mongo DB
h3. Couch DB
Note:
The 'simply_stored' implementation is only partly complete (admin_flag strategy works). Feel free to roll your own implementation for your favorite ORM/Data store.
h2. Install
gem install roles_generic
h2. Role strategy configuration
The following demonstrates some examples of role strategy configuration.
h3. Strategy: admin_flag
Example: Default model configuration:
h3. Strategy: one_role
Example: Customizing model names:
Here the Role class is configured to be named 'Rolle' (Danish translation). If no :role_class options is passed, the default role class 'Role' is used (if the Role class is defined).
Note: The customizing of the Role class model is not yet complete. The generator and such still needs to be updated... Feel free to assist!
h2. Roles generator
A Rails 3 generator is included to update an existing User model with a roles strategy and a set of valid roles. The Generic Roles generator doesn't work for a persistent model. In that case use a dedicated implementation for the ORM (data store) used (see above).
h3. Usage example
rails g roles_generic:roles --strategy admin_flag --roles guest admin
h2. Role strategies
The following role strategies are built-in:
Inline roles (attribute in User model):
Separate Role model:
Embedded Role model (Document stores only):
Currently the embedded strategies have only been implemented for Mongoid.
See "Roles strategy configuration":https://github.com/kristianmandrup/roles_generic/wiki/Roles-strategy-configuration for more info
h2. Roles APIs
The full Roles API is described in these Wiki pages:
h3. Using Roles Groups
The Group API allows roles to be grouped.
Example:
Say you have the admin roles:
And the customer roles
You might want to group them like this:
Then you can handle any user with regards to his/her role group relationship like this:
Expect this functionality to soon to be wrapped by Cream helper methods as well ;)
h2. Note on Patches/Pull Requests
h2. Copyright
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.