guarda 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CLAUDE.md +38 -0
- data/lib/guarda/authorization.rb +2 -0
- data/lib/guarda/version.rb +1 -1
- metadata +4 -8
- data/guarda.gemspec +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 830ac445fca08b8bb6ca80668803ee4d65089e5268240ade28ae32c78e0859c5
|
|
4
|
+
data.tar.gz: c0ed99948611035e596f6208da48a4be92688ca27c8ee6334ec155ba4ac03f28
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbd646715e014941f75d5b0a1b3725012eb2a774eb03d713647383a9dc347d1cb9a11a1813275c9fbedab72b3ccba81cb2bb3d0558aecb4c29042f570cb8dc62
|
|
7
|
+
data.tar.gz: c2b37e7eb562b11dd6dd86dfac120cb7b4035c3a2000082749bd71f46c69f842133df5700b031137b581ce70e132039189309a226111c79acdde8fbb7dbcac2d
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## What is Guarda
|
|
6
|
+
|
|
7
|
+
Guarda is a lightweight Ruby authorization gem. It uses Rails' `CurrentAttributes` (`Current.person`) for the authenticated user and convention-based policy class discovery.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle exec rake test # Run full test suite
|
|
13
|
+
bundle exec rake test TEST=test/authorization_test.rb # Run a single test file
|
|
14
|
+
bundle exec rake build # Build the gem
|
|
15
|
+
bundle exec rake release # Release to RubyGems
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
The gem has three core components in `lib/`:
|
|
21
|
+
|
|
22
|
+
- **`guarda.rb`** — Root module. Defines the exception hierarchy: `Guarda::Error`, `NotAuthorizedError`, `AuthorizationNotPerformedError`, `PolicyFinder::NotFoundError`.
|
|
23
|
+
- **`guarda/authorization.rb`** — An `ActiveSupport::Concern` included in controllers. Provides `authorize(record=nil)`, `policy(controller, record=nil)`, and `verify_authorization_performed`. The `policy` method is also exposed as a view helper.
|
|
24
|
+
- **`guarda/policy_finder.rb`** — Resolves controller paths to policy classes by convention (e.g., `"posts"` → `PostsPolicy`, `"admin/tests"` → `Admin::TestsPolicy`). Uses `safe_constantize`.
|
|
25
|
+
|
|
26
|
+
## Policy Convention
|
|
27
|
+
|
|
28
|
+
Policy classes are plain Ruby classes named `{Controller}Policy` with predicate methods matching action names (e.g., `index?`, `show?`, `update?`). They receive an optional record in their constructor. The authenticated user is accessed via `Current.person` inside the policy.
|
|
29
|
+
|
|
30
|
+
## Test Setup
|
|
31
|
+
|
|
32
|
+
Tests use Minitest with `ActiveSupport::TestCase`. The `test/test_helper.rb` defines mock objects: a `Controller` class that includes `Guarda::Authorization`, test policy classes (`TestsPolicy`, `Admin::TestsPolicy`), and a `Record` struct.
|
|
33
|
+
|
|
34
|
+
## Dependencies
|
|
35
|
+
|
|
36
|
+
- Ruby >= 3.1.0
|
|
37
|
+
- `activesupport ~> 7.1` (runtime)
|
|
38
|
+
- `minitest`, `minitest-reporters`, `rake` (development)
|
data/lib/guarda/authorization.rb
CHANGED
data/lib/guarda/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: guarda
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdullah Hashim
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -50,17 +49,16 @@ dependencies:
|
|
|
50
49
|
- - ">="
|
|
51
50
|
- !ruby/object:Gem::Version
|
|
52
51
|
version: 1.6.1
|
|
53
|
-
description:
|
|
54
52
|
email:
|
|
55
53
|
- abdul@hey.com
|
|
56
54
|
executables: []
|
|
57
55
|
extensions: []
|
|
58
56
|
extra_rdoc_files: []
|
|
59
57
|
files:
|
|
58
|
+
- CLAUDE.md
|
|
60
59
|
- LICENSE.txt
|
|
61
60
|
- README.md
|
|
62
61
|
- Rakefile
|
|
63
|
-
- guarda.gemspec
|
|
64
62
|
- lib/guarda.rb
|
|
65
63
|
- lib/guarda/authorization.rb
|
|
66
64
|
- lib/guarda/policy_finder.rb
|
|
@@ -72,7 +70,6 @@ licenses:
|
|
|
72
70
|
metadata:
|
|
73
71
|
homepage_uri: https://www.guidedrails.com
|
|
74
72
|
source_code_uri: https://github.com/Guided-Rails/guarda
|
|
75
|
-
post_install_message:
|
|
76
73
|
rdoc_options: []
|
|
77
74
|
require_paths:
|
|
78
75
|
- lib
|
|
@@ -87,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
84
|
- !ruby/object:Gem::Version
|
|
88
85
|
version: '0'
|
|
89
86
|
requirements: []
|
|
90
|
-
rubygems_version: 3.
|
|
91
|
-
signing_key:
|
|
87
|
+
rubygems_version: 3.6.9
|
|
92
88
|
specification_version: 4
|
|
93
89
|
summary: Another authorization gem
|
|
94
90
|
test_files: []
|
data/guarda.gemspec
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/guarda/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "guarda"
|
|
7
|
-
spec.version = Guarda::VERSION
|
|
8
|
-
spec.authors = ["Abdullah Hashim"]
|
|
9
|
-
spec.email = ["abdul@hey.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "Another authorization gem"
|
|
12
|
-
spec.homepage = "https://www.guidedrails.com"
|
|
13
|
-
spec.license = "MIT"
|
|
14
|
-
spec.required_ruby_version = ">= 3.1.0"
|
|
15
|
-
|
|
16
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
-
spec.metadata["source_code_uri"] = "https://github.com/Guided-Rails/guarda"
|
|
18
|
-
|
|
19
|
-
spec.files = Dir.chdir(__dir__) do
|
|
20
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
|
21
|
-
(File.expand_path(f) == __FILE__) ||
|
|
22
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
spec.bindir = "exe"
|
|
27
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
28
|
-
spec.require_paths = ["lib"]
|
|
29
|
-
|
|
30
|
-
spec.add_development_dependency "activesupport", "~> 7.1", ">= 7.1.3"
|
|
31
|
-
spec.add_development_dependency "minitest-reporters", "~> 1.6", ">= 1.6.1"
|
|
32
|
-
end
|