ae_easy-qa 0.0.5 → 0.0.6

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: febdd0bea00e94dc6dc192aed9f91816c0bf0460dce74f88ec8ff72bf5677846
4
- data.tar.gz: 5611aae1a6bcf50c4a9282643e44bdbeb5343410dc8b8c4b0001660c5eeaf82f
3
+ metadata.gz: 39b3bb783aba608c9fc02ce779d6f544c28281481e61d806e4bcf6777095c9dc
4
+ data.tar.gz: bfc986330408834be4ad1a2a9a6e47554193cda1264558bf808d463c359aab95
5
5
  SHA512:
6
- metadata.gz: 888b3ceac73bd866cafb17c05378ee8bd5b6c9a3da448b0002448f747c05ba13e227eb0a7e99a823327e55b5927aa65d650b341009b8f3d259fd2b1a3eaa3700
7
- data.tar.gz: dfbe11520a99b2f0a8bfe742c4c9c80eeed1d87469121911873f3511c1fc35889bf565bb52a407cb468e6e70568d6760da6ce5d9c7478e1f7402b8a6d20efd04
6
+ metadata.gz: 04ca90a48e189e8dd9cbe025d1858b4554a7ffb5be9a4bc93f19ea65efaf3c59af9e165db78a8491c46561e0d70347adcc195623afe3c20660249b07ce61abaf
7
+ data.tar.gz: 6668959be7bae4c7ff1208e1a34483901e23c26c6ad8aeb607303de33d19346d2712d529bc17486d35e0538571a6920c13a427cafefca96a0a70a990f85a1f6b
@@ -6,6 +6,7 @@ require 'ae_easy/qa/validate_rules'
6
6
  require 'ae_easy/qa/validate_type'
7
7
  require 'ae_easy/qa/validate_value'
8
8
  require 'ae_easy/qa/validate_groups'
9
+ require 'ae_easy/qa/save_output'
9
10
  require 'answersengine'
10
11
  require 'time'
11
12
 
@@ -18,15 +19,14 @@ module AeEasy
18
19
  def initialize(data=nil, options={})
19
20
  load_config
20
21
  @data = data
21
- @errors = { errored_items: [] }
22
22
  end
23
23
 
24
- def validate_internal
25
- ValidateInternal.new(config).run
24
+ def validate_internal(outputs)
25
+ ValidateInternal.new(config, outputs).run
26
26
  end
27
27
 
28
- def validate_external
29
- ValidateExternal.new(data, errors, config).run
28
+ def validate_external(outputs, collection_name)
29
+ ValidateExternal.new(data, config, outputs, collection_name).run
30
30
  end
31
31
 
32
32
  private
@@ -0,0 +1,49 @@
1
+ module AeEasy
2
+ module Qa
3
+ class SaveOutput
4
+ attr_reader :errors, :collection_name, :outputs, :summary
5
+
6
+ def initialize(errors, collection_name, outputs)
7
+ @errors = errors
8
+ @collection_name = collection_name
9
+ @outputs = outputs
10
+ @summary = Hash.new(0)
11
+ end
12
+
13
+ def run
14
+ save_group_errors
15
+ save_errors
16
+ save_summary
17
+ end
18
+
19
+ private
20
+
21
+ def save_group_errors
22
+ errors.each{|error_name, value|
23
+ if error_name != :errored_items
24
+ outputs << { error_name => 'fail', '_collection' => collection_name }
25
+ summary[error_name] += 1
26
+ end
27
+ }
28
+ end
29
+
30
+ def save_errors
31
+ errors[:errored_items].each do |errored_item|
32
+ errored_item[:failures].each do |failure|
33
+ key = "#{failure.keys.first.to_s}_#{failure.values.first.to_s}"
34
+ summary[key] += 1
35
+ end
36
+ errored_item['_collection'] = collection_name
37
+ outputs << errored_item
38
+ end
39
+ end
40
+
41
+ def save_summary
42
+ if summary.any?
43
+ summary['_collection'] = "#{collection_name}_summary"
44
+ outputs << summary
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,18 +1,21 @@
1
1
  module AeEasy
2
2
  module Qa
3
3
  class ValidateExternal
4
- attr_reader :data, :errors, :config
4
+ attr_reader :data, :errors, :config, :outputs, :collection_name
5
5
 
6
- def initialize(data, errors, config)
6
+ def initialize(data, config, outputs, collection_name)
7
7
  @data = data
8
- @errors = errors
9
8
  @config = config
9
+ @outputs = outputs
10
+ @collection_name = collection_name
11
+ @errors = { errored_items: [] }
10
12
  end
11
13
 
12
14
  def run
13
15
  begin
14
16
  ValidateGroups.new(data, errors).run
15
17
  ValidateRules.new(data, errors, config['individual_validations']).run if config
18
+ SaveOutput.new(errors, collection_name, outputs).run
16
19
  return errors
17
20
  rescue StandardError => e
18
21
  puts "An error has occurred: #{e}"
@@ -1,17 +1,18 @@
1
1
  module AeEasy
2
2
  module Qa
3
3
  class ValidateInternal
4
- attr_reader :scrapers, :rules
4
+ attr_reader :scrapers, :rules, :outputs
5
5
 
6
- def initialize(config)
6
+ def initialize(config, outputs)
7
7
  @scrapers = config['scrapers']
8
8
  @rules = config['individual_validations']
9
+ @outputs = outputs
9
10
  end
10
11
 
11
12
  def run
12
13
  begin
13
14
  scrapers.each do |scraper_name, collections|
14
- ValidateScraper.new(scraper_name, collections, rules).run
15
+ ValidateScraper.new(scraper_name, collections, rules, outputs).run
15
16
  end
16
17
  rescue StandardError => e
17
18
  puts "An error has occurred: #{e}"
@@ -21,17 +22,18 @@ module AeEasy
21
22
  end
22
23
 
23
24
  class ValidateScraper
24
- attr_reader :scraper_name, :collections, :rules
25
+ attr_reader :scraper_name, :collections, :rules, :outputs
25
26
 
26
- def initialize(scraper_name, collections, rules)
27
+ def initialize(scraper_name, collections, rules, outputs)
27
28
  @scraper_name = scraper_name
28
29
  @collections = collections
29
30
  @rules = rules
31
+ @outputs = outputs
30
32
  end
31
33
 
32
34
  def run
33
35
  collections.each do |collection_name|
34
- ValidateCollection.new(scraper_name, collection_name, total_records(collection_name), rules).run
36
+ ValidateCollection.new(scraper_name, collection_name, total_records(collection_name), rules, outputs).run
35
37
  end
36
38
  end
37
39
 
@@ -47,29 +49,27 @@ module AeEasy
47
49
  end
48
50
 
49
51
  class ValidateCollection
50
- attr_reader :scraper_name, :collection_name, :total_records, :rules, :errors
52
+ attr_reader :scraper_name, :collection_name, :total_records, :rules, :errors, :outputs
51
53
 
52
- def initialize(scraper_name, collection_name, total_records, rules)
54
+ def initialize(scraper_name, collection_name, total_records, rules, outputs)
53
55
  @scraper_name = scraper_name
54
56
  @collection_name = collection_name
55
57
  @total_records = total_records
56
58
  @rules = rules
59
+ @outputs = outputs
57
60
  @errors = { errored_items: [] }
58
61
  end
59
62
 
60
63
  def run
61
64
  ValidateGroups.new(data, errors).run
62
- #could create the errors hash inside ValidateRules?
63
- #errors = ValidateRules.new(data, config).run
64
65
  ValidateRules.new(data, errors, rules).run
65
- #should have a class that saves the output and the summary output
66
- #SaveOutput.new(errors, output_collection_name).run
66
+ SaveOutput.new(errors, outputs_collection_name, outputs).run
67
67
  end
68
68
 
69
69
  private
70
70
 
71
- def output_collection_name
72
- @output_collection_name ||= "#{scraper_name}_#{collection_name}"
71
+ def outputs_collection_name
72
+ @outputs_collection_name ||= "#{scraper_name}_#{collection_name}"
73
73
  end
74
74
 
75
75
  def data
@@ -86,7 +86,6 @@ module AeEasy
86
86
  data
87
87
  end
88
88
  end
89
-
90
89
  end
91
90
  end
92
91
  end
@@ -1,5 +1,5 @@
1
1
  module AeEasy
2
2
  module Qa
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
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.5
4
+ version: 0.0.6
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-06-17 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: answersengine
@@ -78,6 +78,7 @@ files:
78
78
  - bin/setup
79
79
  - lib/ae_easy/qa.rb
80
80
  - lib/ae_easy/qa/helpers.rb
81
+ - lib/ae_easy/qa/save_output.rb
81
82
  - lib/ae_easy/qa/validate_external.rb
82
83
  - lib/ae_easy/qa/validate_groups.rb
83
84
  - lib/ae_easy/qa/validate_internal.rb