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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e2ac1483d7b8253bb52289a1c81727bbfc15f47a60f0f03ab7f7f9c78e38d69
4
- data.tar.gz: ab18b48276b107552e3335cd8dfc17e98d04a764aef9655ca369d40b5c6fae10
3
+ metadata.gz: 82a5402ccb9e68d9057911ef1adae45ba41ef7347c31301d2ae394d22965e740
4
+ data.tar.gz: ee2e235452e7c2f11587024f455a63dbd41fbe1f4e9f481d7320c548c513e6b8
5
5
  SHA512:
6
- metadata.gz: 259728e11d27c2c78829433b4dcd6e6d6f869533c7637002b6823c498523e5bc8353a2ffcd307556d09b94095ea435cf963bf4ae6fe88234ae1e6fe90fecc437
7
- data.tar.gz: 6383a6bd485a6ea5ad111095bc8df0e961c570ef54206f5139eb7c8ad2b742501d427656e79a26e2838b3a0ccef224401a9e8c564ceb9eadb55b14d78600f152
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(object = nil, petitioner = nil, permissions: nil, parameters: nil, law_class: nil)
26
- object ||= @record || try(:controller_name)&.singularize&.camelize&.safe_constantize
27
- petitioner ||= try(:current_user)
28
- permissions ||= petitioner.try(:permissions)
29
- law_class ||= object.try(:conjugate, Law::LawBase)
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: object, params: parameters)
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 ||= try(:action_name)
42
- parameters ||= try(:params)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Law
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
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.8
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: 2021-06-09 00:00:00.000000000 Z
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.1.4
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: []