law 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/law.rb +2 -0
- data/lib/law/judgement.rb +15 -5
- data/lib/law/petition.rb +6 -0
- data/lib/law/statute_base.rb +2 -0
- data/lib/law/statutes/compliance.rb +27 -0
- data/lib/law/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b0b434177cd64675d5c94ad0ce5a25cd68e29d381320b06df44def8ba4749dd
|
4
|
+
data.tar.gz: fa0dec022a5174b587299ba8bbeacde58ed05050593c404805c0bf8afd82c8cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b03be210deacc8a7eab971bbe4073c803a8cb9e7a4493afd7f689f62fa0eda5e6461135f869295dfffb57b44cc46c3ee21537c633971ddf2b9905bd9450e703f
|
7
|
+
data.tar.gz: c9ffa4c048f433bef6d7cd12b9decfe028252751b8ed66fa677e0cd94e8e0215089059347bdb9cdc3e9639d6664027f3496c1411c9af2b73a25869dd793708b6
|
data/lib/law.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_support/core_ext/enumerable"
|
5
|
+
require "active_support/hash_with_indifferent_access"
|
5
6
|
|
6
7
|
require "spicery"
|
7
8
|
|
@@ -27,4 +28,5 @@ module Law
|
|
27
28
|
|
28
29
|
class NotAuthorizedError < Error; end
|
29
30
|
class InjunctionError < NotAuthorizedError; end
|
31
|
+
class ComplianceError < NotAuthorizedError; end
|
30
32
|
end
|
data/lib/law/judgement.rb
CHANGED
@@ -15,7 +15,7 @@ module Law
|
|
15
15
|
|
16
16
|
attr_reader :petition, :violations, :applied_regulations
|
17
17
|
|
18
|
-
delegate :statute, :applicable_regulations, to: :petition, allow_nil: true
|
18
|
+
delegate :statute, :applicable_regulations, :compliant?, to: :petition, allow_nil: true
|
19
19
|
|
20
20
|
def initialize(petition)
|
21
21
|
@petition = petition
|
@@ -39,20 +39,30 @@ module Law
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def judge!
|
42
|
+
raise AlreadyJudgedError if adjudicated?
|
43
|
+
|
42
44
|
if statute&.unregulated?
|
43
45
|
@applied_regulations = [ nil ]
|
44
46
|
return true
|
45
47
|
end
|
46
48
|
|
49
|
+
ensure_jurisdiction
|
50
|
+
reckon!
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def ensure_jurisdiction
|
47
58
|
raise InjunctionError if applicable_regulations.blank?
|
48
|
-
raise
|
59
|
+
raise ComplianceError unless compliant?
|
60
|
+
end
|
49
61
|
|
62
|
+
def reckon!
|
50
63
|
@applied_regulations = applicable_regulations.map { |regulation| regulation.new(petition: petition) }
|
51
64
|
@violations = applied_regulations.reject(&:valid?)
|
52
|
-
|
53
65
|
raise NotAuthorizedError unless authorized?
|
54
|
-
|
55
|
-
true
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
data/lib/law/petition.rb
CHANGED
@@ -18,5 +18,11 @@ module Law
|
|
18
18
|
statute.regulations.select { |regulation| permission_list.include? regulation.key }
|
19
19
|
end
|
20
20
|
memoize :applicable_regulations
|
21
|
+
|
22
|
+
def compliant?
|
23
|
+
return applicable_regulations.any? unless statute.full_compliance_required?
|
24
|
+
|
25
|
+
statute.regulations == applicable_regulations
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
data/lib/law/statute_base.rb
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative "statutes/regulations"
|
4
4
|
require_relative "statutes/laws"
|
5
|
+
require_relative "statutes/compliance"
|
5
6
|
|
6
7
|
# A **Statute** restricts actions to **Actors** by enforcing a collection of **Permissions**.
|
7
8
|
module Law
|
8
9
|
class StatuteBase < Spicerack::RootObject
|
9
10
|
include Law::Statutes::Regulations
|
10
11
|
include Law::Statutes::Laws
|
12
|
+
include Law::Statutes::Compliance
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A **Statute** is a collection of imposed **Regulations** with some **Compliance** rules.
|
4
|
+
module Law
|
5
|
+
module Statutes
|
6
|
+
module Compliance
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def full_compliance_required?
|
11
|
+
@require_full_compliance.present?
|
12
|
+
end
|
13
|
+
|
14
|
+
def inherited(base)
|
15
|
+
base.require_full_compliance if full_compliance_required?
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def require_full_compliance
|
22
|
+
@require_full_compliance = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/law/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/law/rspec/shoulda_matcher_helper.rb
|
203
203
|
- lib/law/spec_helper.rb
|
204
204
|
- lib/law/statute_base.rb
|
205
|
+
- lib/law/statutes/compliance.rb
|
205
206
|
- lib/law/statutes/laws.rb
|
206
207
|
- lib/law/statutes/regulations.rb
|
207
208
|
- lib/law/version.rb
|