law 0.1.3 → 0.1.4

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: e74cd15524ae8f0731bcb351779158496be3fa61a49e7e3553a53a0bfd5fdcff
4
- data.tar.gz: fa7920650d8debe57a1bbcafa2b6cabf1e9b617783a3f22edc9568a9e7eea359
3
+ metadata.gz: 7470b14c46e6d6c2120b369f16b8f5504a2435e471605586105299c1fb3e6556
4
+ data.tar.gz: 6bc9fa7d019b36e63c1be6a86a9d42b1e3ed30abf1cf418e21390f9e5badda6c
5
5
  SHA512:
6
- metadata.gz: cb1bda1a9cfbbe9205453a318d2ef783e2adc62ce13bdea457e76c93f07194d4531265c0d3284eb866c722aed16853696d6283a7d590de5f8a90145ef441b7bd
7
- data.tar.gz: 866e1524f3d77b29d872ade4758faa389889a114a6a287b68fae0772fa5371658a4be22cc9d5c1cdb87e6f046068c864a4af3838a5ed35cf965d8aadace18de8
6
+ metadata.gz: db2018f3a5d3c6ddb374f7587095a90a1b2079b43d5366f611d7355c3f1d04d5d9f1dbc2a66a9a4ae97ef95d36b452fc0de533f6144b56ba5c2d29587a60f4eb
7
+ data.tar.gz: d46aae4f1e368b8c2e9a204b4b3eec71c974c5f1426a02bd1edb613e90a02cb779dd80de5d16591d5b81481cd08b7cc92bb36bed3c22bf077755385c4ed68a6b
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
18
+ delegate :statute, :applicable_regulations, to: :petition, allow_nil: true
19
19
 
20
20
  def initialize(petition)
21
21
  @petition = petition
@@ -39,7 +39,7 @@ module Law
39
39
  end
40
40
 
41
41
  def judge!
42
- if statute.unregulated?
42
+ if statute&.unregulated?
43
43
  @applied_regulations = [ nil ]
44
44
  return true
45
45
  end
@@ -8,22 +8,32 @@ module Law
8
8
 
9
9
  included do
10
10
  class_attribute :actions, instance_writer: false, default: HashWithIndifferentAccess.new
11
+ class_attribute :revoked_actions, instance_writer: false, default: HashWithIndifferentAccess.new
11
12
 
12
- delegate :statute_for_action?, to: :class
13
+ delegate :statute_for_action?, :revoked_action?, to: :class
13
14
  end
14
15
 
15
16
  class_methods do
16
17
  def inherited(base)
17
18
  base.actions = actions.dup
19
+ base.revoked_actions = revoked_actions.dup
18
20
  super
19
21
  end
20
22
 
23
+ def revoked_action?(action)
24
+ revoked_actions[action].present?
25
+ end
26
+
21
27
  def statute_for_action?(action)
22
28
  actions[action].present?
23
29
  end
24
30
 
25
31
  private
26
32
 
33
+ def revoke_action(*input_actions)
34
+ input_actions.each { |action| revoked_actions[action] = true }
35
+ end
36
+
27
37
  def define_action(*input_actions, enforces: nil)
28
38
  raise ArgumentError, "invalid statute: #{enforces}" unless enforceable?(enforces)
29
39
 
@@ -14,6 +14,8 @@ module Law
14
14
  end
15
15
 
16
16
  def petition_for_action(action)
17
+ return if revoked_action?(action)
18
+
17
19
  Law::Petition.new(
18
20
  statute: actions[action] || _default_statute,
19
21
  source: source,
@@ -6,3 +6,4 @@ require_relative "custom_matchers/be_imposed_by"
6
6
  require_relative "custom_matchers/define_action"
7
7
  require_relative "custom_matchers/have_default_statute"
8
8
  require_relative "custom_matchers/impose_regulations"
9
+ require_relative "custom_matchers/revoke_action"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RSpec matcher that tests revoking of statutes in laws.
4
+ #
5
+ # class ExampleStatute < ApplicationStatute
6
+ # end
7
+ #
8
+ # class CommonLaw < ApplicationStatute
9
+ # define_action :new, enforces: ExampleRegulation
10
+ # define_action :create, enforces: ExampleRegulation
11
+ # define_action :edit
12
+ # end
13
+ #
14
+ # class ExampleLaw < CommonLaw
15
+ # revoke_action :new, :edit
16
+ # end
17
+ #
18
+ # RSpec.describe ExampleLaw, type: :law do
19
+ # it { is_expected.to revoke_action :new, :edit }
20
+ # end
21
+
22
+ RSpec::Matchers.define :revoke_action do |*actions|
23
+ match do
24
+ actions.each { |action| expect(test_subject.revoked_action?(action)).to eq true }
25
+ end
26
+ description { "revoke #{"action".pluralize(actions.length)} #{actions.join(", ")}" }
27
+ failure_message { "expected #{test_subject} to revoke #{"action".pluralize(actions.length)} #{actions.join(", ")}" }
28
+ failure_message_when_negated do
29
+ "expected #{test_subject} not to revoke #{"action".pluralize(actions.length)} #{actions.join(", ")}"
30
+ end
31
+
32
+ def test_subject
33
+ subject.is_a?(Class) ? subject : subject.class
34
+ end
35
+ 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.3"
4
+ VERSION = "0.1.4"
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
@@ -198,6 +198,7 @@ files:
198
198
  - lib/law/rspec/custom_matchers/define_action.rb
199
199
  - lib/law/rspec/custom_matchers/have_default_statute.rb
200
200
  - lib/law/rspec/custom_matchers/impose_regulations.rb
201
+ - lib/law/rspec/custom_matchers/revoke_action.rb
201
202
  - lib/law/rspec/shoulda_matcher_helper.rb
202
203
  - lib/law/spec_helper.rb
203
204
  - lib/law/statute_base.rb