law 0.1.8 → 0.1.9
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/lib/law/legalize.rb +34 -8
- data/lib/law/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82a5402ccb9e68d9057911ef1adae45ba41ef7347c31301d2ae394d22965e740
|
4
|
+
data.tar.gz: ee2e235452e7c2f11587024f455a63dbd41fbe1f4e9f481d7320c548c513e6b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b366d740089901b37ed3387283430fbc4d57e223114a8c540c5577e56d5bd57582cd4dc2ddb0c2e9e2a94722580d88e210f7279b28a4e80958c1c9fa19d06c80
|
7
|
+
data.tar.gz: eb6d5a005328b97587a2d37c5de99ff94b1d449ad9407cab17b0a6f2962570bb0d1f48a12f240f5d1916ec1f0c15a4b40f8cd7411311cb67cd3b24a1cf44486b
|
data/lib/law/legalize.rb
CHANGED
@@ -22,15 +22,15 @@ module Law
|
|
22
22
|
judgement.try(:violations) || []
|
23
23
|
end
|
24
24
|
|
25
|
-
def law(
|
26
|
-
|
27
|
-
petitioner ||=
|
28
|
-
permissions ||= petitioner
|
29
|
-
law_class ||=
|
25
|
+
def law(target = nil, petitioner = nil, permissions: nil, parameters: nil, law_class: nil)
|
26
|
+
target ||= law_default_target
|
27
|
+
petitioner ||= law_default_petitioner
|
28
|
+
permissions ||= law_permissions_for(petitioner)
|
29
|
+
law_class ||= law_class_for(target)
|
30
30
|
|
31
31
|
raise ArgumentError, "a Law is required" unless law_class.is_a?(Class)
|
32
32
|
|
33
|
-
law_class.new(permissions: permissions, source: petitioner, target:
|
33
|
+
law_class.new(permissions: permissions, source: petitioner, target: target, params: parameters)
|
34
34
|
end
|
35
35
|
|
36
36
|
def authorize!(action = nil, **options)
|
@@ -38,8 +38,8 @@ module Law
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def authorize(action = nil, object: nil, petitioner: nil, permissions: nil, parameters: nil, law_class: nil)
|
41
|
-
action ||=
|
42
|
-
parameters ||=
|
41
|
+
action ||= law_default_action
|
42
|
+
parameters ||= law_default_params
|
43
43
|
|
44
44
|
raise ArgumentError, "an action is required" if action.nil?
|
45
45
|
|
@@ -47,5 +47,31 @@ module Law
|
|
47
47
|
@judgement = law(object, petitioner, **options).authorize(action)
|
48
48
|
authorized?
|
49
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def law_default_target
|
54
|
+
@record || try(:controller_name)&.singularize&.camelize&.safe_constantize
|
55
|
+
end
|
56
|
+
|
57
|
+
def law_default_petitioner
|
58
|
+
try(:current_user)
|
59
|
+
end
|
60
|
+
|
61
|
+
def law_permissions_for(petitioner)
|
62
|
+
petitioner.try(:permissions)
|
63
|
+
end
|
64
|
+
|
65
|
+
def law_class_for(target)
|
66
|
+
target.try(:conjugate, Law::LawBase)
|
67
|
+
end
|
68
|
+
|
69
|
+
def law_default_action
|
70
|
+
try(:action_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def law_default_params
|
74
|
+
try(:params)
|
75
|
+
end
|
50
76
|
end
|
51
77
|
end
|
data/lib/law/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: law
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
8
8
|
- Brandon Trumpold
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -233,7 +233,7 @@ metadata:
|
|
233
233
|
homepage_uri: https://github.com/Freshly/law/tree/master
|
234
234
|
source_code_uri: https://github.com/Freshly/law/tree/master
|
235
235
|
changelog_uri: https://github.com/Freshly/law/blob/master/CHANGELOG.md
|
236
|
-
post_install_message:
|
236
|
+
post_install_message:
|
237
237
|
rdoc_options: []
|
238
238
|
require_paths:
|
239
239
|
- lib
|
@@ -248,8 +248,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
- !ruby/object:Gem::Version
|
249
249
|
version: '0'
|
250
250
|
requirements: []
|
251
|
-
rubygems_version: 3.
|
252
|
-
signing_key:
|
251
|
+
rubygems_version: 3.5.9
|
252
|
+
signing_key:
|
253
253
|
specification_version: 4
|
254
254
|
summary: Give illegal operations a whole new meaning with this policy enforcement
|
255
255
|
test_files: []
|