law 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/law/judgement.rb +2 -2
- data/lib/law/laws/actions.rb +11 -1
- data/lib/law/laws/petitions.rb +2 -0
- data/lib/law/rspec/custom_matchers.rb +1 -0
- data/lib/law/rspec/custom_matchers/revoke_action.rb +35 -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: 7470b14c46e6d6c2120b369f16b8f5504a2435e471605586105299c1fb3e6556
|
4
|
+
data.tar.gz: 6bc9fa7d019b36e63c1be6a86a9d42b1e3ed30abf1cf418e21390f9e5badda6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
42
|
+
if statute&.unregulated?
|
43
43
|
@applied_regulations = [ nil ]
|
44
44
|
return true
|
45
45
|
end
|
data/lib/law/laws/actions.rb
CHANGED
@@ -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
|
|
data/lib/law/laws/petitions.rb
CHANGED
@@ -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
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.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
|