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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2faeb187ecbed96767befe2d2108e62e79d9b80517d81a86b6e2078ef17da226
4
- data.tar.gz: b1f66ca28aecbd68e167a289c42e87cf4e768fb94ab6cc7f4ef5148dfc41fa7e
3
+ metadata.gz: 8071e0d012d60099bd30afaaabe7274fe4572a88686115e9b8db86fe880a0734
4
+ data.tar.gz: 212b5f27a5309d3cd638e354d8a41cbd77dcf0a5b9f22d5976e04403cea200a4
5
5
  SHA512:
6
- metadata.gz: 5b6d1e1401ca3acc40d412143c2835e1f84433bc07e8ebda19a5f9af27e4d6fd4d088cdf6a7e68aa1a1841159a6c3c721cda069883a5ba05b6797005e1c805a5
7
- data.tar.gz: 1a268b957386d9f2ae2596a4924865ee646dc4baf7312c2d50dea51da98e0e3340aa1decffdbcf4307906fcfe43dffdabbfaab7f71f33636f7c8aed99877e526
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[name.to_sym] = validator
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[name.to_sym] = validator
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 |name, validator|
45
- !validator.as(Callable).call(input)
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.keys.join(", ") if failed_preconditions.any?
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 { |name, validator| !validator.as(Callable).call(output) }
55
- raise PostConditionError, failed_postconditions.keys.join(", ") if failed_postconditions.any?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plumbing
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard-procedure-plumbing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahoul Baruah