<commit_before># DeviseAuthorizable

DeviseAuthorizable adds user roles and user authorization to
[Devise](https://github.com/plataformatec/devise). You can assign roles like
*admin* or *moderator* to users and define what they can read, create, update
and/or destroy in your App.

```ruby
@user.can? :read, Post
=> true

@user.can? :manage, Post
=> false

@user.add_role :admin

@user.can? :manage, Post
=> true
```

DeviseAuthorizable supports Rails 4 and Devise 3.


## Installation

You must have installed and configured Devise first. Follow the guides on
https://github.com/plataformatec/devise.

Add DeviseAuthorizable to your Gemfile and run the bundle command to install it:

```ruby
gem 'devise_authorizable'
```

After the Gem is installed you need to run the install generator:

```console
rails generate devise_authorizable:install
```

This will include the DeviseAuthorizable module to Devise, create the ability
class that you use to setup abilities (aka permissions) and generate migrations.

Thats it. Read on for how to setup roles and add abilities.


## Add and manage user roles

At the moment roles can only be managed via the Rails console.
Someone who would like to add a browser based role manager is very welcome.

```ruby
# To get all roles of the current user:
@user.roles
=> [:guest]

# To check if the user has the specified role:
@user.has_role? :admin
=> true

# To add a role 'admin' to the user:
@user.add_role :admin

# To remove the 'admin' role from the user
@user.delete_role :admin
```

## Define abilities

DeviseAuthorizable uses [CanCan](https://github.com/ryanb/cancan) to define
and check abilities for users.

The install generator added a ability class to your application. If your Devise
model is called *User* the ability model name is *UserAbility*. This is where<commit_msg>fix README<commit_after># DeviseAuthorizable

DeviseAuthorizable adds user roles and user authorization to
[Devise](https://github.com/plataformatec/devise). You can assign roles like
*admin* or *moderator* to users and define what they can read, create, update
and/or destroy in your App.

```ruby
@user.can? :read, Post
=> true

@user.can? :manage, Post
=> false

@user.add_role :admin

@user.can? :manage, Post
=> true
```

DeviseAuthorizable supports Rails 4 and Devise 3.


## Installation

You must have installed and configured Devise first. Follow the guides on
https://github.com/plataformatec/devise.

Add DeviseAuthorizable to your Gemfile and run the bundle command to install it:

```ruby
gem 'devise_authorizable'
```

After the Gem is installed you need to run the install generator:

```console
rails generate devise_authorizable:install
```

This will include the DeviseAuthorizable module to Devise, create the ability
class that you use to setup abilities (aka permissions) and generate migrations.

Thats it. Read on for how to setup roles and add abilities.


## Add and manage user roles

At the moment roles can only be managed via the Rails console.
Someone who would like to add a browser based role manager is very welcome.

```ruby
# To get all roles of the current user:
@user.roles
=> [:guest]

# To check if the user has the specified role:
@user.has_role? :admin
=> false

# To add a role 'admin' to the user:
@user.add_role :admin

# To remove the 'admin' role from the user
@user.delete_role :admin
```

## Define abilities

DeviseAuthorizable uses [CanCan](https://github.com/ryanb/cancan) to define
and check abilities for users.

The install generator added a ability class to your application. If your Devise
model is called *User* the ability model name is *UserAbility*. This is where
{'fraction_non_alphanumeric': 0.0800438596491228, 'fraction_numerical': 0.0010964912280701754, 'mean_word_length': 4.579510703363915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3150524', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1046, 'n_words': 498}