ae_easy-qa 0.0.29 → 0.0.30

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: 1ce6bef710db31f58f1b5aa8be6c56a1236c7ccf351ce7182e25a2591b5b88ec
4
- data.tar.gz: 5c1df465ff7784212593c3eea51600e81194eb95a0aaaf272c136990487f3456
3
+ metadata.gz: ed84890a1e1c73d0b31bd188f1fb159083141e74cffcb8b97e8e9e2636bb3cb0
4
+ data.tar.gz: 3abeb7da3deee197330ff9520267570585ce425b44987f2425cf20df623c5d9f
5
5
  SHA512:
6
- metadata.gz: 63bd32612cd55d7da0bae8d6af5844d14503eb0ce14dd991b059c53eccfaec80f090dd850da1aa31f063796e6df9a79dd80dc8c297420e52f8cdea5685436197
7
- data.tar.gz: f74ccf359c5f783d7fb2af685ace70dd44aa6ec8466f9b98966feb175c4aacd1eb18a9e6e7b4de12ef9a71fadc665b60ad0f30325e20948b50e9c59ae8915be9
6
+ metadata.gz: e07fbcce3494f1f07b1848ddb86a036c20d27df581cd665da00dc3dcf56b42e569d7b19fe1da11cde300d5eddf2dd2c345dc50dbd7b346d119da4929c10c9920
7
+ data.tar.gz: 53fdcb4d8883a0ff1f13b5e207adcb53c09a26a4ae9a75e5003e5006fadca3d18dfd05affdbbee25a7111837941c9c082208031565fe2ed4ee14cf45c62ed7d8
@@ -6,6 +6,26 @@ module AeEasy
6
6
  errored_item[:failures][error_name.to_sym] = 'fail'
7
7
  errored_item[:item] = data_hash if errored_item[:data].nil?
8
8
  end
9
+
10
+ def pass_if?(if_params, data_hash)
11
+ field_name = if_params.keys.first
12
+ condition_hash = if_params[field_name]
13
+ case condition_hash.keys.first
14
+ when 'value'
15
+ value_hash = condition_hash['value'] #Ex: {"equal"=>"A"}
16
+ if value_hash['equal']
17
+ data_hash[field_name] == value_hash['equal']
18
+ elsif value_hash['regex']
19
+ data_hash[field_name].to_s =~ Regexp.new(value_hash['regex'], true)
20
+ elsif value_hash['less_than']
21
+ data_hash[field_name] < value_hash['less_than']
22
+ elsif value_hash['greater_than']
23
+ data_hash[field_name] > value_hash['greater_than']
24
+ else
25
+ raise StandardError.new("The if condition '#{value_hash}' is unknown.")
26
+ end
27
+ end
28
+ end
9
29
  end
10
30
  end
11
31
  end
@@ -27,12 +27,12 @@ module AeEasy
27
27
  options.each{|validation, value|
28
28
  case validation
29
29
  when 'type'
30
- ValidateType.new(data_hash, field_to_validate, value, rules, errored_item).run if options['required']
30
+ ValidateType.new(data_hash, field_to_validate, value, rules, errored_item).run
31
31
  when 'value'
32
- ValidateValue.new(data_hash, field_to_validate, value, errored_item).run if options['required']
32
+ ValidateValue.new(data_hash, field_to_validate, value, errored_item).run
33
33
  when 'length'
34
- validate_length(data_hash, field_to_validate, value) if options['required']
35
- when /required|threshold/
34
+ validate_length(data_hash, field_to_validate, value)
35
+ when /required|threshold|if/
36
36
  nil
37
37
  else
38
38
  unknown_validation_error(validation) if validation !~ /format/
@@ -46,8 +46,17 @@ module AeEasy
46
46
 
47
47
  def passes_required_check?(options, data_hash, field_to_validate)
48
48
  if options['required'] == true && fails_required_check?(data_hash, field_to_validate)
49
- add_errored_item(data_hash, field_to_validate, 'required')
50
- false
49
+ if options['if']
50
+ if pass_if?(options['if'], data_hash)
51
+ add_errored_item(data_hash, field_to_validate, 'required')
52
+ false
53
+ else
54
+ true
55
+ end
56
+ else
57
+ add_errored_item(data_hash, field_to_validate, 'required')
58
+ false
59
+ end
51
60
  else
52
61
  true
53
62
  end
@@ -13,33 +13,17 @@ module AeEasy
13
13
  end
14
14
 
15
15
  def run
16
- condition_exists? ? handle_conditions : main_value_check
16
+ if_exists? ? handle_if : main_value_check
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def condition_exists?
21
+ def if_exists?
22
22
  !params['if'].nil?
23
23
  end
24
24
 
25
- def handle_conditions
26
- field_name = params['if'].keys.first
27
- condition_hash = params['if'][field_name]
28
- case condition_hash.keys.first
29
- when 'value'
30
- value_hash = condition_hash['value'] #Ex: {"equal"=>"A"}
31
- if value_hash['equal']
32
- main_value_check if data_hash[field_name] == value_hash['equal']
33
- elsif value_hash['regex']
34
- main_value_check if data_hash[field_name].to_s =~ Regexp.new(value_hash['regex'], true)
35
- elsif params['less_than']
36
- main_value_check if data_hash[field_name] < value_hash['less_than']
37
- elsif params['greater_than']
38
- main_value_check if data_hash[field_name] > value_hash['greater_than']
39
- else
40
- raise StandardError.new("The if condition '#{value_hash}' is unknown.")
41
- end
42
- end
25
+ def handle_if
26
+ main_value_check if pass_if?(params['if'], data_hash)
43
27
  end
44
28
 
45
29
  def main_value_check
@@ -1,5 +1,5 @@
1
1
  module AeEasy
2
2
  module Qa
3
- VERSION = "0.0.29"
3
+ VERSION = "0.0.30"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_easy-qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lynam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-19 00:00:00.000000000 Z
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: answersengine