hubbado-policy 1.0.1 → 1.1.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: 8338406be7ea8412d5c7d81fee557858ac5327d9f84ef048a662b04f381dcb41
4
- data.tar.gz: 4f58a42ba93883f48735ab220f9ff8047f360b41ea9d0a6e35c8c21c9a78318e
3
+ metadata.gz: bae8f5de291d165b188ec93876c8de9ba6a977d3137411df9bcc8529b7bc9347
4
+ data.tar.gz: 7702e0686f9bb660596608e1191a28b0db5fa913e174ac4b37501e2a5634c4c8
5
5
  SHA512:
6
- metadata.gz: 4e084a506c028722b36741f9d93f0f0cf6385d04c8aedbab34b3053eaaeb804e5734bc93466351f2c4ecfe486ea5763ba6f5ed2700877fbeb445a828eb61e1b2
7
- data.tar.gz: 48fc0f6b56cd3dc53da3bc79e73fb9ba41bd35795e3e9da0b3e8b9d82164aafa07cb656047debfb8bcd067ca916b5b84e0e3012cb0bc1497d051ff23d870f480
6
+ metadata.gz: 27efa98093df93083e47dda2f457634602e356a7448a61fd18a0cd0939eb531bfec567ba57ee397e7126f822e7cf174adc6b7b805e15905bdac16ec4bcb5a1fd
7
+ data.tar.gz: 1bd2be57259ca1df1a6602305e0d81e2800fff493f72798ae98a64500f87f65e4eb0f3acf5d268fe69adfb87b06944883fe6477a9b58b004946f8b0c6fed8969
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.0] - 2025-05-20
9
+
10
+ ### Added
11
+ - Control to mimic policies
12
+
8
13
  ## [1.0.1] - 2025-05-20
9
14
 
10
15
  Bump because rubygems does not allow repushing the same version even if it is yanked.
data/README.md CHANGED
@@ -131,6 +131,34 @@ en:
131
131
  denied: "Access denied"
132
132
  ```
133
133
 
134
+ ### Testing
135
+
136
+ Policies can be mimiced using a built-in control
137
+
138
+ ```ruby
139
+ module Control
140
+ module Policies
141
+ module ArticlePolicy
142
+ def self.example(attributes = nil)
143
+ attributes ||= {}
144
+ Policy.new(**attributes)
145
+ end
146
+
147
+ class Policy < ::Hubbado::Policy::Controls::Policy
148
+ mimic ::ArticlePolicy
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ mimic_policy = Control::Policies::ArticlePolicy.example
155
+ mimic_policy.view? # returns the value from the real policy
156
+
157
+
158
+ mimic_policy = Control::Policies::ArticlePolicy.example(view: ArticlePolicy.denied)
159
+ mimic_policy.view? # returns false
160
+ ```
161
+
134
162
  ## Result Objects
135
163
 
136
164
  Result objects represent the outcome of a policy check, containing:
@@ -276,18 +304,14 @@ Hubbado Policy is designed to work seamlessly with the [eventide-project/depende
276
304
  require 'dependency'; Dependency.activate
277
305
  require 'hubbado-policy'
278
306
 
279
- class Services
280
- dependency :permission_service, PermissionService
281
- dependency :audit_logger, AuditLogger
282
- end
283
-
284
307
  # Then use them in your policy
285
308
  class ArticlePolicy < HubbadoPolicy::Policy
286
309
  dependency :permission_service, PermissionService
287
310
  dependency :audit_logger, AuditLogger
288
311
 
289
312
  def configure
290
- Services.configure(self)
313
+ PermissionService.configure(self)
314
+ AuditLogger.configure(self)
291
315
  end
292
316
 
293
317
  define_policy :publish do
@@ -324,7 +348,7 @@ class ArticleScope < HubbadoPolicy::Scope
324
348
  dependency :visibility_service, VisibilityService
325
349
 
326
350
  def configure
327
- Services.configure(self)
351
+ VisibilityService.configure(self)
328
352
  end
329
353
 
330
354
  def self.default_scope
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubbado-policy"
3
- s.version = "1.0.1"
3
+ s.version = "1.1.0"
4
4
  s.summary = "A lightweight, flexible policy framework for Ruby applications"
5
5
 
6
6
  s.authors = ["Hubbado Devs"]
@@ -0,0 +1,27 @@
1
+ module Hubbado
2
+ module Policy
3
+ module Controls
4
+ class Policy
5
+ def self.mimic(policy_class)
6
+ policy_class.policies.each do |policy|
7
+ send(:attr_writer, policy)
8
+
9
+ define_method policy do
10
+ instance_variable_get("@#{policy}") || ::Hubbado::Policy::Base.denied
11
+ end
12
+
13
+ define_method "#{policy}?" do
14
+ send(policy).permitted?
15
+ end
16
+ end
17
+ end
18
+
19
+ def initialize(policies = {})
20
+ policies.each do |policy, result|
21
+ send("#{policy}=", result)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require "hubbado/policy/controls/policy"
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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubbado Devs
@@ -120,6 +120,8 @@ files:
120
120
  - hubbado-policy.gemspec
121
121
  - lib/hubbado-policy.rb
122
122
  - lib/hubbado/policy/base.rb
123
+ - lib/hubbado/policy/controls.rb
124
+ - lib/hubbado/policy/controls/policy.rb
123
125
  - lib/hubbado/policy/railtie.rb
124
126
  - lib/hubbado/policy/result.rb
125
127
  - lib/hubbado/policy/scope.rb