https://github.com/sirscriptalot/polizia
https://github.com/sirscriptalot/polizia
authorization
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/sirscriptalot/polizia
- Owner: sirscriptalot
- License: mit
- Created: 2018-02-07T21:09:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-07T23:19:49.000Z (over 8 years ago)
- Last Synced: 2025-01-11T14:49:12.016Z (over 1 year ago)
- Topics: authorization
- Language: Ruby
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polizia
A small authorization library for implementing "policy" objects.
Polizia is a minimal clone of the popular Pundit gem.
## Installation
`gem install polizia`
## Usage
```ruby
require 'polizia'
class Account
attr_accessor :user
def initialize(user:)
@user = user
end
end
class AccountPolicy < Polizia
def create?
user.guest?
end
def update?(account)
account.user == user
end
def delete?(account)
account.user == user
end
end
class User
def guest?
false
end
end
user = User.new
account = Account.new(user: user)
policy = AccountPolicy.new(user)
policy.create? # false
policy.update?(account) # true
policy.delete?(account) # true
```