README.md in rolify-3.1.0 vs README.md in rolify-3.2.0.rc2

- old
+ new

@@ -11,13 +11,14 @@ 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.1 -* ActiveRecord ORM <b>or</b> Mongoid -* supports ruby 1.8/1.9, REE, JRuby and Rubinius +* Rails >= 3.1 +* ActiveRecord >= 3.1 <b>or</b> Mongoid >= 3.0 +* supports ruby 1.9, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode) +* support of ruby 1.8 has been dropped due to Mongoid 3.0 that only supports 1.9 new hash syntax ## Installation In <b>Rails 3</b>, add this to your Gemfile and run the +bundle+ command. @@ -52,12 +53,46 @@ ``` rake db:migrate ``` -### 3. Add a role to a user +### 3.1 Configure your user model +This gem adds the `rolify` method to your User class. You can also specify optional callbacks* on the user for when roles are added or removed: + +```ruby + class User < ActiveRecord::Base + rolify :before_add => :before_add_method + + def :before_add_method(role) + # do something before it gets added + end + end +``` + +The `rolify` method accepts the following callback* options: + +- `before_add` +- `after_add` +- `before_remove` +- `after_remove` + +*PLEASE NOTE: callbacks are currently only supported using ActiveRecord ORM. Mongoid will support association callbacks in its 3.1 release (Mongoid current version is 3.0.x) + +### 3.2 Configure your resource models + +In the resource models you want to apply roles on, just add ``resourcify`` method. +For example, on this ActiveRecord class: + +```ruby +class Forum < ActiveRecord::Base + resourcify +end +``` + +### 4. Add a role to a user + To define a global role: ```ruby user = User.find(1) user.add_role :admin @@ -77,11 +112,11 @@ user.add_role :moderator, Forum ``` That's it ! -### 4. Check roles +### 5. Role queries To check if a user has a global role: ```ruby user = User.find(1) @@ -123,11 +158,11 @@ => true user.has_role? :moderator, Forum.last => true ``` -### 5. Resource roles querying +### 6. Resource roles querying Starting from rolify 3.0, you can search roles on instance level or class level resources. #### Instance level @@ -158,9 +193,10 @@ ## Resources * [Wiki](https://github.com/EppO/rolify/wiki) * [Usage](https://github.com/EppO/rolify/wiki/Usage): all the available commands * [Tutorial](https://github.com/EppO/rolify/wiki/Tutorial): how to use [rolify](http://eppo.github.com/rolify) with [Devise](https://github.com/plataformatec/devise) and [CanCan](https://github.com/ryanb/cancan). +* [Amazing tutorial](http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html) provided by [RailsApps](http://railsapps.github.com/) ## Questions or Problems? If you have any issue or feature request with/for rolify, please add an [issue on GitHub](https://github.com/EppO/rolify/issues) or fork the project and send a pull request. \ No newline at end of file