u-authorization 2.2.0 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eed3ce0a228018f007c58ae1c1e70ae5b782b841f98ae3baad6519c6fc40531
4
- data.tar.gz: 2201d27e01a1f206bf395334b536596dd88fb05760a986c1e29fe4a9253e3f2e
3
+ metadata.gz: 51c049fdf0f6232070f3f1bb66812b92401d5fea6ff171990d07eea0e7f81693
4
+ data.tar.gz: 34456d500170bafe3d018687e3bbd3c46b3d373918829150549d2992297b88f8
5
5
  SHA512:
6
- metadata.gz: 467a55948c8864903d7024c250dd4b9a93244fbb379dc16aa7d91f1f983ba7f5da6d14c6af8e39a52a9639aa30cad129dc84ad2e56bb34b4bfd6245491845809
7
- data.tar.gz: 6c28d09268e034911b19b66a192b53057d21c8c0995fc16e3d1754249da968eeb51d71b074782e1867b2885c67437da25c8c3fb235b7826048f957dc35440514
6
+ metadata.gz: d62f986439e59cff7acedd82d2d0f608e0a28bbd9870f0d95347b987a13b217f2e71df86c7f32d3e47147273296bf50abe54843e93e6ad9cc69e9a535129730d
7
+ data.tar.gz: d3dfde01673ddf71ff0ec631d35b42275ccfd6f85e74755fa3e6b1ae8303b6ff1ffefe9fb6bf30c51ab11440173529385b57f85dd66d27c85011867aa492f912
@@ -0,0 +1,41 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+
9
+ pull_request:
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ name: Ruby ${{ matrix.ruby }}
15
+ permissions:
16
+ contents: read
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "3.4", "4.0", head]
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ with:
24
+ persist-credentials: false
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ - name: Install bundler
30
+ run: gem install bundler -v 2.4.22
31
+ if: ${{ matrix.ruby == '2.7' || matrix.ruby == '3.0' }}
32
+ - name: Bundle install
33
+ run: bundle install
34
+ - name: Run tests
35
+ run: bundle exec rake test
36
+ - name: Upload coverage to Qlty
37
+ uses: qltysh/qlty-action/coverage@v2
38
+ if: ${{ matrix.ruby == '3.4' && !github.base_ref }}
39
+ with:
40
+ token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
41
+ files: coverage/.resultset.json
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ .DS_Store
2
+
1
3
  /.bundle/
2
4
  /.yardoc
3
5
  /_yardoc/
@@ -6,3 +8,8 @@
6
8
  /pkg/
7
9
  /spec/reports/
8
10
  /tmp/
11
+
12
+ Gemfile.lock
13
+
14
+ .tool-versions
15
+ tags
data/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [3.0.0] - 2026-06-01
11
+
12
+ ### Added
13
+
14
+ - This `CHANGELOG.md`, following the [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/) format and backfilled to cover every tagged release.
15
+ - GitHub Actions CI that runs the test suite across Ruby 2.7 through the current development build, with coverage uploaded to Qlty.
16
+ - A rewritten, comprehensive `README.md`, an API stability notice, and a `CLAUDE.md` with notes for contributors.
17
+ - `bin/setup` and `bin/console` scripts.
18
+ - `homepage_uri`, `source_code_uri`, and `bug_tracker_uri` entries in the gem metadata.
19
+
20
+ ### Changed
21
+
22
+ - Raised the minimum Ruby version to `>= 2.7.0` (was `>= 2.2.0`). Ruby 2.2 through 2.6 are end of life.
23
+ - Bumped the `rake` development dependency to `~> 13.0` (was `~> 10.0`).
24
+
25
+ ### Fixed
26
+
27
+ - Ruby 3.0+ compatibility in `Micro::Authorization::Model#add_policies`. It no longer relies on `Method#to_proc` auto-splatting the `[key, value]` pair, which raised an `ArgumentError` on Ruby 3.0 and later.
28
+
29
+ ### Removed
30
+
31
+ - Travis CI configuration (`.travis.yml`), replaced by GitHub Actions.
32
+ - `Gemfile.lock` is no longer tracked; it is regenerated per environment.
33
+
34
+ ## [2.3.0] - 2019-08-04
35
+
36
+ ### Changed
37
+
38
+ - A policy's context must now be a Hash. `current_user` (and its `user` alias) reads `context[:user]` and falls back to `context[:current_user]`; passing a non-Hash context to use directly as the user is no longer supported.
39
+ - Clearer `ArgumentError` message from `Micro::Authorization::Model#add_policies` when it is given something other than a Hash.
40
+
41
+ ### Removed
42
+
43
+ - The deprecation warning on the permission checker's `required_features`. It is now a plain alias of `#features`.
44
+
45
+ ## [2.2.0] - 2019-07-30
46
+
47
+ ### Added
48
+
49
+ - Multi-role permissions. `Micro::Authorization::Permissions.new` and `Micro::Authorization::Model.build` accept an array of roles and grant the union of their permissions, so a feature is allowed when any role allows it.
50
+
51
+ ### Deprecated
52
+
53
+ - The permission checker's `required_features`, in favor of `required_context`. This was reverted in 2.3.0, where `#features` became the method name and `required_features` a plain alias.
54
+
55
+ ## [2.1.0] - 2019-07-29
56
+
57
+ ### Added
58
+
59
+ - `:to_permit` as the context key for permission checks in `Micro::Authorization::Model.build`, with `:permissions` kept as an alias.
60
+ - README badges and Travis CI configuration.
61
+
62
+ ## [2.0.0] - 2019-07-26
63
+
64
+ ### Added
65
+
66
+ - First tagged release of the `Micro::Authorization` architecture: the `Micro::Authorization::Model.build` entry point, the data-driven `Permissions` layer (roles as hashes with `any` / `only` / `except` rules and context matching, including dot-notation segments), and the `Micro::Authorization::Policy` base class for record-level checks that denies undefined predicates by default.
67
+ - Each class organized into its own file under `lib/micro/authorization/`, with the test suite running on Minitest.
68
+
69
+ [Unreleased]: https://github.com/u-gems/u-authorization/compare/v3.0.0...HEAD
70
+ [3.0.0]: https://github.com/u-gems/u-authorization/compare/v2.3.0...v3.0.0
71
+ [2.3.0]: https://github.com/u-gems/u-authorization/compare/v2.2.0...v2.3.0
72
+ [2.2.0]: https://github.com/u-gems/u-authorization/compare/v2.1.0...v2.2.0
73
+ [2.1.0]: https://github.com/u-gems/u-authorization/compare/v2.0.0...v2.1.0
74
+ [2.0.0]: https://github.com/u-gems/u-authorization/releases/tag/v2.0.0
data/CLAUDE.md ADDED
@@ -0,0 +1,124 @@
1
+ # CLAUDE.md
2
+
3
+ Notes for AI assistants working in `u-authorization`.
4
+
5
+ ## Golden rule: feature-complete, keep it running
6
+
7
+ `u-authorization` is feature-complete. There are no plans to add new features. The only ongoing work is keeping the gem compatible and running on current and future Ruby versions, plus the usual bug fixes, docs, and CI upkeep.
8
+
9
+ That means two things for any task here:
10
+
11
+ - **Don't add features or change the public API.** The API is frozen and backward compatible. If a task as stated would require a new feature or a breaking change, stop and surface that, then propose a compatibility-only path.
12
+ - **Major version bumps are for dependency-floor changes only** (dropping an old Ruby from the supported matrix) per SemVer. They do not signal a behavior break. Note that this gem is pure Ruby with no ActiveModel dependency, so the support matrix is Ruby-only.
13
+
14
+ ## How to work in this repo
15
+
16
+ ### 1. Think before coding
17
+
18
+ **Don't assume. Don't hide confusion. Surface tradeoffs.**
19
+
20
+ - State assumptions explicitly. If uncertain, ask.
21
+ - If multiple interpretations exist, present them — don't pick silently.
22
+ - If a simpler approach exists, say so. Push back when warranted.
23
+ - If something is unclear, stop. Name what's confusing. Ask.
24
+
25
+ ### 2. Simplicity first
26
+
27
+ **Minimum code that solves the problem. Nothing speculative.**
28
+
29
+ - No features beyond what was asked.
30
+ - No abstractions for single-use code.
31
+ - No "flexibility" or "configurability" that wasn't requested.
32
+ - No error handling for impossible scenarios.
33
+ - If you write 200 lines and it could be 50, rewrite it.
34
+
35
+ Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes,
36
+ simplify.
37
+
38
+ ### 3. Surgical changes
39
+
40
+ **Touch only what you must. Clean up only your own mess.**
41
+
42
+ - Don't "improve" adjacent code, comments, or formatting.
43
+ - Don't refactor things that aren't broken.
44
+ - Match existing style, even if you'd do it differently.
45
+ - If you notice unrelated dead code, mention it — don't delete it.
46
+ - Remove imports/variables/functions that _your_ changes orphaned. Don't
47
+ remove pre-existing dead code unless asked.
48
+
49
+ The test: every changed line should trace directly to the user's request.
50
+
51
+ ### 4. Goal-driven execution
52
+
53
+ **Define success criteria. Loop until verified.**
54
+
55
+ Turn vague tasks into verifiable goals:
56
+
57
+ - "Add validation" → "Write tests for invalid inputs, then make them pass"
58
+ - "Fix the bug" → "Write a test that reproduces it, then make it pass"
59
+ - "Refactor X" → "Ensure tests pass before and after"
60
+
61
+ For multi-step work, state a brief plan with a verification check per step.
62
+
63
+ ---
64
+
65
+ ## What this is
66
+
67
+ `u-authorization` is a small, zero-runtime-dependency Ruby library for
68
+ authorization and role management, living under `lib/micro/authorization/`.
69
+ Its public namespace is `Micro::Authorization`, built from three cohesive
70
+ pieces:
71
+
72
+ - **`Permissions`** (`permissions.rb` + `permissions/`) — role-based,
73
+ per-feature permission checks (`to?`, `to_not?`, context matching via
74
+ `Checker` / `ForEachFeature`).
75
+ - **`Policy`** (`policy.rb`) — per-subject authorization policies, instantiated
76
+ with a context and the caller's permissions.
77
+ - **`Model`** (`model.rb`) — the entry point that ties permissions, policies,
78
+ and a context together (`Model.build`, `#to` / `#policy`, `#map`).
79
+
80
+ `require 'u-authorization'` (or `require 'micro/authorization'`) loads the lot.
81
+ It is a pure-Ruby gem with **no ActiveModel/Rails dependency** — it's designed
82
+ to drop into Rails controllers (`[controller_name, action_name]` style
83
+ contexts) but doesn't require Rails. Because it's a published gem, behavior
84
+ changes — especially anything affecting the public API or the supported `ruby`
85
+ matrix — are highly visible.
86
+
87
+ ## Running tests
88
+
89
+ ```bash
90
+ bundle exec rake test # full suite (also the default `rake` task)
91
+ ```
92
+
93
+ The suite is plain Minitest with SimpleCov coverage; there are no Appraisals
94
+ or ActiveModel axes (the gem has no Rails dependency). `bin/setup` reinstalls
95
+ the bundle; `bin/console` opens an IRB session with the gem loaded.
96
+
97
+ To test across Ruby versions locally, use mise — `.tool-versions` lists the
98
+ supported versions. CI (`.github/workflows/ci.yml`) runs the suite across the
99
+ full `ruby` matrix (2.7 → head). Tests are the success criterion for any
100
+ behavior change — write or update a test first, then make it pass (rule 4).
101
+
102
+ ## CHANGELOG and README are part of every change
103
+
104
+ Both files are user-facing; keep them in sync with the code.
105
+
106
+ - `CHANGELOG.md` follows [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/). Record every user-visible change (behavior change, bug fix, dependency-floor bump, security fix) under the appropriate section of `[Unreleased]`. Pure internal-refactor or CI-only changes generally don't need an entry.
107
+ - `README.md` badges and the **Required Ruby version** section near the top reference the supported Ruby bounds; update them when those bounds move. If you change a documented API, update the relevant **Usage** section in the same commit.
108
+
109
+ ## Bumping the version
110
+
111
+ 1. Edit `lib/micro/authorization/version.rb` — change
112
+ `Micro::Authorization::VERSION`. Follow [SemVer](https://semver.org/):
113
+ patch for fixes, minor for additive user-visible changes, major for
114
+ breaking changes. For this gem a major bump means an old Ruby was dropped
115
+ from the supported matrix, not a behavior break.
116
+ 2. Add a new top entry in `CHANGELOG.md` (`## [X.Y.Z] - YYYY-MM-DD`), move the
117
+ relevant `[Unreleased]` notes under it, and add a matching compare link at
118
+ the bottom (`[X.Y.Z]: …/compare/vPREV...vX.Y.Z`).
119
+ 3. If the supported Ruby matrix moved, update the Ruby badge and the
120
+ **Required Ruby version** section in `README.md`, and double-check the
121
+ `required_ruby_version` in `u-authorization.gemspec` and the CI matrix in
122
+ `.github/workflows/ci.yml` agree.
123
+
124
+ Don't tag, push, or `gem release` — humans do that.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rodrigo@ysimplicity.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,10 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in u-authorization.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
3
10
  group :test do
4
11
  gem 'minitest', '~> 5.11', '>= 5.11.3'
5
12
  gem 'minitest-reporters', '~> 1.3', '>= 1.3.6'
6
- gem 'simplecov', require: false
13
+ gem 'ostruct', '~> 0.6.3' if RUBY_VERSION >= '3.5'
14
+ gem 'simplecov', '~> 0.22.0', require: false
7
15
  end
8
-
9
- # Specify your gem's dependencies in u-authorization.gemspec
10
- gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Rodrigo Serradura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.