From bb1465a92f6eeaddb2275f451adddfe1949ff789 Mon Sep 17 00:00:00 2001 From: Gustavo Beathyate Date: Tue, 9 Jul 2013 13:59:56 -0500 Subject: [PATCH] bumb version and improve documentation --- README.md | 67 +++++++++++++++++++++++++++++++++++++++- lib/guachiman/version.rb | 2 +- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5912684..766b49e 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,69 @@ Or install it yourself as: Usage ----- -TODO: Write usage instructions here +Include it in your `Gemfile` + +```ruby +gem 'guachiman' +``` + +Run `bundle install` + +Run `rails g guachiman:install` + +This will generate a `Permission.rb` file in `app/models`. + +Include `Guachiman::Permissible` in `ApplicationController` and implemente a `current_user` method there. + +```ruby +include Guachiman::Permissible + +def current_user + @current_user ||= User.find_by_auth_token(cookies[:auth_token]) if cookies[:auth_token] +end +``` + +That's it, now you can describe your permissions in this way: + +```ruby +class Permission + include Guachiman::Permissions + include Guachiman::Params + + attr_reader :user + + def initialize current_user + @user = current_user + + if user.nil? + guest + elsif user.admin? + admin + else + member + end + end + + private + + def guest + allow :sessions, [:new, :create, :destroy] + allow :identities, [:new, :create] + allow :passwords, [:new, :create] + + allow_param :user, [:name, :email, :password] + end + + def member + guest + allow :identities, [:show, :edit, :update] + allow :passwords, [:edit, :update] + end + + def admin + allow_all! + end +end +``` + +The method `allow` takes a controller params key and an array of actions. The method `allow_param` takes a model params key and an array of attributes. The method `allow_all!` is a convinience method to allow all controlles, actions and parameteres. \ No newline at end of file diff --git a/lib/guachiman/version.rb b/lib/guachiman/version.rb index 00d5f8c..3623ad5 100644 --- a/lib/guachiman/version.rb +++ b/lib/guachiman/version.rb @@ -1,3 +1,3 @@ module Guachiman - VERSION = '0.1.2' + VERSION = '0.1.3' end