Project

polizia

0.0
No commit activity in last 3 years
No release in over 3 years
Polizia
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.2
 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

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