Sha256: ea875e2f4b0aeaa485923c82ab9defdf8571c434e6d6a6e530642bd8a039a14a

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

# Rolypoly

[![Gem Version](https://badge.fury.io/rb/rolypoly.png)](http://badge.fury.io/rb/rolypoly)
[![Build Status](https://travis-ci.org/sportngin/rolypoly.png)](https://travis-ci.org/sportngin/rolypoly)

Allow certain roles access to certain controller actions.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'rolypoly'
```

And then execute:

```bash
$> bundle
```

## Usage

```ruby
class ApplicationController < ActionController::Base
  def current_roles
    current_user.roles
  end

  rescue_from(Rolypoly::FailedRoleCheckError) do
    render text: "Failed Authorization!", status: 401
  end
end

class UsersController < ApplicationController
  include Rolypoly::ControllerRoleDSL

  def index
    # ...
  end
  restrict(:index).to(:admin)
  # OR
  allow(:admin).to_access(:index)

  # Do a bunch at once
  allow(:scorekeeper, :official).to_access(:show, :score)
  def show
    # ...
  end

  def score
    # ...
  end

  # Allow admin role to access all actions of this controller
  allow(:admin).to_all

  # Make action public
  restrict(:landing).to_none
  publicize :landing

  def landing
    # ...
  end

  # Give up and make all public
  all_public
end
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rolypoly-0.0.5 README.md
rolypoly-0.0.4 README.md
rolypoly-0.0.3 README.md
rolypoly-0.0.2 README.md