hubbado-policy 1.2.1 → 1.3.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: fb076b8106150620c0cbe71b07bf2cf8f3c83234d6269fdb01395726fe83833f
4
- data.tar.gz: e40f7c0787d5aafb14a41f889093fb488d0ed0c9faaaf4dcb81cc839c6d15f96
3
+ metadata.gz: 85715105fb8d91ba36116e0fe32fc87806a48960898d9e5b9802af20bba64e67
4
+ data.tar.gz: 532065ab325a09f66d6f2dc18e89db1b77f2c2032f45ee424f6dc196dde99c8f
5
5
  SHA512:
6
- metadata.gz: c79b6a45e34b558a77e3aaaba9caa6e6963cab5e97f7ceff932fdf1150a75c7d94386baf173508923c6e87bcc0b7e5e5f1e69325cc64ba5d878b1c052980b835
7
- data.tar.gz: e5f01ac761f171f755196057dbfe667171bccc5165c5ebd2cef1fa73df490f3ef6a5a50aa0065d343b1440ec2e1e076911c3b0f95953d6868d2ddcbd2b8631cc
6
+ metadata.gz: ff8d518316ca3e959685b16f9b76afc893686ff02d237de6ccc9573e14b2ac2114bc20bb0a69af9bb5af3bb8105732123b3d486ae1da3ba24e6fbb0054adac1a
7
+ data.tar.gz: 793021cd69698ace3607c10d68cab0811032f2c93e1d2b71c497e5405ebd2f4b6141eabb023b2b2bb34b4eae7155fff0caa1f62912a35dad3267445aab2d515e
data/CHANGELOG.md CHANGED
@@ -2,9 +2,15 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.0] - 2025-06-03
9
+
10
+ ### Added
11
+
12
+ - Ability to configure the i18n_scope for a non-generic denied reason
13
+
8
14
  ## [1.2.1] - 2025-06-02
9
15
 
10
16
  ### Fixed
data/README.md CHANGED
@@ -131,6 +131,27 @@ en:
131
131
  denied: "Access denied"
132
132
  ```
133
133
 
134
+ You can also specify a custom i18n scope when returning denied results:
135
+
136
+ ```ruby
137
+ define_policy :edit do
138
+ # Use a different i18n scope for this specific denial
139
+ return denied(:not_authorized, i18n_scope: "custom_errors.article")
140
+
141
+ permitted
142
+ end
143
+ ```
144
+
145
+ Both the class method and instance method versions of `denied` support the `i18n_scope` parameter:
146
+
147
+ ```ruby
148
+ # Class method
149
+ ArticlePolicy.denied(:custom_reason, i18n_scope: "errors.custom")
150
+
151
+ # Instance method
152
+ policy.denied(:custom_reason, i18n_scope: "errors.custom")
153
+ ```
154
+
134
155
  ### Testing
135
156
 
136
157
  Policies can be mimiced using a built-in control
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubbado-policy"
3
- s.version = "1.2.1"
3
+ s.version = "1.3.0"
4
4
  s.summary = "A lightweight, flexible policy framework for Ruby applications"
5
5
 
6
6
  s.authors = ["Hubbado Devs"]
@@ -48,13 +48,14 @@ module Hubbado
48
48
  # Define this in a subclass if there are dependencies to be configure
49
49
  template_method :configure
50
50
 
51
- def self.denied(reason = nil, data: nil)
51
+ def self.denied(reason = nil, data: nil, i18n_scope: nil)
52
+ i18n_scope ||= self.i18n_scope
52
53
  reason ||= :denied
53
54
  Result.new(false, reason, i18n_scope: i18n_scope, data: data)
54
55
  end
55
56
 
56
57
  def self.permitted
57
- Result.new(true, :permitted, i18n_scope: i18n_scope)
58
+ Result.new(true, :permitted)
58
59
  end
59
60
 
60
61
  def self.i18n_scope
@@ -72,8 +73,8 @@ module Hubbado
72
73
  self.class == other.class && user == other.user && record == other.record
73
74
  end
74
75
 
75
- def denied(reason = nil, data: nil)
76
- self.class.denied(reason, data: data)
76
+ def denied(reason = nil, data: nil, i18n_scope: nil)
77
+ self.class.denied(reason, data: data, i18n_scope: i18n_scope)
77
78
  end
78
79
 
79
80
  def permitted
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubbado-policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubbado Devs