standard-procedure-plumbing 0.5.1 → 0.5.2
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 +4 -4
- data/lib/plumbing/pipeline/contracts.rb +17 -9
- data/lib/plumbing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8071e0d012d60099bd30afaaabe7274fe4572a88686115e9b8db86fe880a0734
|
4
|
+
data.tar.gz: 212b5f27a5309d3cd638e354d8a41cbd77dcf0a5b9f22d5976e04403cea200a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82e7bf5617439df2e00886e7d95e9c4215e5f2e7dcf91a6a5de3673cd132bbc069c301fd0cdeb4cd315faff76981a4282898da66771be57ce19c7d9589fa7a30
|
7
|
+
data.tar.gz: c64ee286c7fec70b9025bd32ceaa39379751d26f7e7947934f07c5651f62f564407a87a4227fd2e4202c042b2d9db7df48008e67ba06aea9f15b269b7606cd15
|
@@ -7,7 +7,7 @@ module Plumbing
|
|
7
7
|
# @yield [Object] input the input data to be validated
|
8
8
|
# @yieldreturn [Boolean] true to accept the input, false to reject it
|
9
9
|
def pre_condition name, &validator
|
10
|
-
pre_conditions
|
10
|
+
pre_conditions << ConditionValidator.new(name.to_s, validator)
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param [String] contract_class the class name of the [Dry::Validation::Contract] that will be used to validate the input data
|
@@ -20,17 +20,21 @@ module Plumbing
|
|
20
20
|
# @yield [Object] output the output data to be validated
|
21
21
|
# @yieldreturn [Boolean] true to accept the output, false to reject it
|
22
22
|
def post_condition name, &validator
|
23
|
-
post_conditions
|
23
|
+
post_conditions << ConditionValidator.new(name.to_s, validator)
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
+
class ConditionValidator < Struct.new(:name, :validator)
|
29
|
+
def call(input) = validator.call input
|
30
|
+
end
|
31
|
+
|
28
32
|
def pre_conditions
|
29
|
-
@pre_conditions ||=
|
33
|
+
@pre_conditions ||= []
|
30
34
|
end
|
31
35
|
|
32
36
|
def post_conditions
|
33
|
-
@post_conditions ||=
|
37
|
+
@post_conditions ||= []
|
34
38
|
end
|
35
39
|
|
36
40
|
def validate_contract_for input
|
@@ -41,18 +45,22 @@ module Plumbing
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def validate_preconditions_for input
|
44
|
-
failed_preconditions = pre_conditions.select do |
|
45
|
-
!validator.
|
48
|
+
failed_preconditions = pre_conditions.select do |validator|
|
49
|
+
!validator.call(input)
|
46
50
|
rescue
|
47
51
|
true
|
48
52
|
end
|
49
|
-
raise PreConditionError, failed_preconditions.
|
53
|
+
raise PreConditionError, failed_preconditions.map(&:name).join(", ") if failed_preconditions.any?
|
50
54
|
input
|
51
55
|
end
|
52
56
|
|
53
57
|
def validate_postconditions_for output
|
54
|
-
failed_postconditions = post_conditions.select
|
55
|
-
|
58
|
+
failed_postconditions = post_conditions.select do |validator|
|
59
|
+
!validator.call(output)
|
60
|
+
rescue
|
61
|
+
true
|
62
|
+
end
|
63
|
+
raise PostConditionError, failed_postconditions.map(&:name).join(", ") if failed_postconditions.any?
|
56
64
|
output
|
57
65
|
end
|
58
66
|
end
|
data/lib/plumbing/version.rb
CHANGED