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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7470b14c46e6d6c2120b369f16b8f5504a2435e471605586105299c1fb3e6556
4
- data.tar.gz: 6bc9fa7d019b36e63c1be6a86a9d42b1e3ed30abf1cf418e21390f9e5badda6c
3
+ metadata.gz: 0b0b434177cd64675d5c94ad0ce5a25cd68e29d381320b06df44def8ba4749dd
4
+ data.tar.gz: fa0dec022a5174b587299ba8bbeacde58ed05050593c404805c0bf8afd82c8cc
5
5
  SHA512:
6
- metadata.gz: db2018f3a5d3c6ddb374f7587095a90a1b2079b43d5366f611d7355c3f1d04d5d9f1dbc2a66a9a4ae97ef95d36b452fc0de533f6144b56ba5c2d29587a60f4eb
7
- data.tar.gz: d46aae4f1e368b8c2e9a204b4b3eec71c974c5f1426a02bd1edb613e90a02cb779dd80de5d16591d5b81481cd08b7cc92bb36bed3c22bf077755385c4ed68a6b
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 AlreadyJudgedError if adjudicated?
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Law
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
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
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