$ show varvet/pundit
Pundit is a Ruby gem providing object-oriented authorization for Rails applications. It defines policy classes (plain Ruby objects) with query methods like `update?` and scope classes for scoping records. The core is a `Pundit::Context` that handles authorization, policy finding, and caching. It integrates with Rails controllers via `Pundit::Authorization` mixin, offering `authorize`, `policy`, `policy_scope`, and strong parameter helpers. It includes RSpec matchers for testing policies and generators for Rails. The architecture is clean, well-tested, and actively maintained.
The LLM identified 2 files worth highlighting for reuse:
Resolves policy and scope classes from a given object (instance, class, symbol, or array for namespacing). Uses recursion to handle nested namespaces, supports `policy_class` method on objects, and falls back to naming convention (`ModelPolicy`). This is a self-contained utility that can be extracted to any Ruby project needing dynamic class resolution based on naming conventions.
Provides a custom RSpec matcher `permit` and a DSL method `permissions` for testing policy classes. The matcher checks multiple permissions against a policy instance and gives descriptive failure messages. The DSL creates example groups with metadata. This is a reusable pattern for building custom RSpec matchers and DSLs for any authorization or permission system.