Skip to content

Commit

Permalink
added LICENSE and README files
Browse files Browse the repository at this point in the history
  • Loading branch information
EppO committed Jun 3, 2011
1 parent fd9d4d6 commit fa565b3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 Florent Monbillard

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
80 changes: 80 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
= Rolify

Very simple Roles library without any authorization enforcement (built to use with cancan) supporting scope on object.

Let's see an example:

user.is_moderator?(Forum.first) => # return false if user is moderator of another Forum

This library was intended to be used with CanCan[https://github.com/ryanb/cancan] and devise[https://github.com/plataformatec/devise/] but should be generic enough to be used by any other authentication/authorization solutions.

== Requirements

* >= Rails 3
* ActiveRecord ORM

== Installation

In <b>Rails 3</b>, add this to your Gemfile and run the +bundle+ command.

gem "rolify"

Alternatively, you can install it as a plugin.

rails plugin install git://github.com/ryanb/cancan.git

== Getting Started

=== 1. Generate Role Modle

First, create your Role model and migration file using this generator:

rails g rolify:role Role User

Role and User classes are the default. You can specify any Role class name you want. This is completly a new file so any name can do the job.
For the User class name, you would probably use the one provided by your authentication solution. rolify just adds some class methods in an existing User class.

=== 2. Run the migration

Let's migrate !

rake db:migrate

=== 3. Add a role to a user

To define a global role:

user = User.find(1)
user.has_role "admin"

To define a role scoped to a resource

user = User.find(2)
user.has_role "moderator", Forum.first

That's it !

=== 4. Check roles

To check if a user has a global role

user = User.find(1)
user.has_role? "admin"
# => true

To check if a user has a role scoped to a resource

user = User.find(2)
user.has_role "moderator", Forum.first
# => true
user.has_role "moderator", Forum.last
# => false

== Questions or Problems?

If you have any issues with rolify which you cannot find the solution to in the tiny README[https://github.com/EppO/rolify], please add an {issue on GitHub}[https://github.com/EppO/rolify/issues] or fork the project and send a pull request.

== TODO

* Write specs
* Write code
Binary file removed lib/generators/rolify/role/.role_generator.rb.swp
Binary file not shown.

0 comments on commit fa565b3

Please sign in to comment.