Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
bumb version and improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Beathyate committed Jul 9, 2013
1 parent c48fe2e commit bb1465a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion lib/guachiman/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Guachiman
VERSION = '0.1.2'
VERSION = '0.1.3'
end

0 comments on commit bb1465a

Please sign in to comment.