hospital 0.8.2 → 0.8.4

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: b7abce524070f1b1275fe021c20e42f046a856c460007c30ab859fc1173c6bfd
4
- data.tar.gz: f5e1eebdaeab9d799524ce3fdbca6efd9e54ae215b5100a77cf3367b08ac4e1a
3
+ metadata.gz: a1074319a2f7179076d1ddf35612df2167dfd2ca66e6e77a488c65727090fff4
4
+ data.tar.gz: 7e1532336e49b8b73c01ee6a519698714fcff224970a5a9f4c23504272b48ba9
5
5
  SHA512:
6
- metadata.gz: 37f5f27286a859bdcb4c54f380ac3f9af6cd9b907310f4434e340ab3e4bce388bcb5369ddfe2f191b5612a5bdc57bbcd9659bbbea5ddcd01d7b8566d055ce3dd
7
- data.tar.gz: 75c6a04304725ebe87adcfff3239d563b7a1a01b04d8af784c127ed68c259d5af609f8a417dfae54a85af38a7dcc9021fb1bfa5733a2e7516c3f8358998e9d73
6
+ metadata.gz: 07633f2b838a3d8bef495212dd3da16953b29ffc94579a4cf9fe94c5ff0d8a8ff5165207eff071999810afc7ba12bf8c8b32c8d12245c6bc08c5071709369b5a
7
+ data.tar.gz: 1d70ff1ea84cfe57c6f8ee32a573105737a78189eeefa980e313d2105d585e5a32279d607afbbd125d21555f0984053754a119270f34363568a89aa3c42af5e8
@@ -13,8 +13,8 @@ module Hospital
13
13
  @buffer << "\n\n## Checking #{text}"
14
14
  end
15
15
 
16
- def put_diagnosis_skipped text
17
- @buffer << "\n\n## Skipped #{text}"
16
+ def put_diagnosis_skipped text, verbose: false
17
+ @buffer << "\n\n## Skipped #{text}" if verbose
18
18
  end
19
19
 
20
20
  def put_summary errors_count, warnings_count, infos_count
@@ -7,20 +7,24 @@ module Hospital
7
7
  class Raw < Base
8
8
 
9
9
  def initialize
10
- @data = {}
10
+ @data = {}
11
11
  @current_group = nil
12
12
  @current_diagnosis = nil
13
13
  end
14
14
 
15
15
  def put_group_header text
16
16
  @current_group = text
17
+ @data[@current_group] ||= {}
17
18
  end
18
19
 
19
20
  def put_diagnosis_header text
20
21
  @current_diagnosis = text
22
+ @data[@current_group][@current_diagnosis] ||= []
21
23
  end
22
24
 
23
- def put_diagnosis_skipped text
25
+ def put_diagnosis_skipped text, verbose: false
26
+ # don't overwrite existing entry (in case of name collision)
27
+ @data[@current_group][text] ||= { 'skipped' => true }
24
28
  end
25
29
 
26
30
  def put_summary errors_count, warnings_count, infos_count
@@ -32,8 +36,6 @@ module Hospital
32
36
  end
33
37
 
34
38
  def put_diagnosis_result result
35
- @data[@current_group] ||= {}
36
- @data[@current_group][@current_diagnosis] ||= []
37
39
  @data[@current_group][@current_diagnosis] << {
38
40
  'type' => result.type,
39
41
  'message' => result.message
@@ -13,8 +13,8 @@ module Hospital
13
13
  @buffer << "\nChecking #{text.h2.indented}"
14
14
  end
15
15
 
16
- def put_diagnosis_skipped text
17
- @buffer << "\nSkipped #{text.h2.indented}"
16
+ def put_diagnosis_skipped text, verbose: false
17
+ @buffer << "\nSkipped #{text.h2.indented}" if verbose
18
18
  end
19
19
 
20
20
  def put_summary errors_count, warnings_count, infos_count
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hospital
4
- VERSION = "0.8.2"
4
+ VERSION = "0.8.4"
5
5
  end
data/lib/hospital.rb CHANGED
@@ -25,10 +25,34 @@ module Hospital
25
25
  end
26
26
 
27
27
  # used to call the checkup for a specific class directly (in specs)
28
+ # respects preconditions: runs preconditions first, skips dependents if any fail
28
29
  def do_checkup(klass, verbose: false, ignore_condition: false)
29
- @@groups.map(&:all_checkups).flatten.select{|cu| cu.klass == klass }.map do |cu|
30
- cu.check verbose: verbose, ignore_condition: ignore_condition
30
+ checkups = @@groups.map(&:all_checkups).flatten.select { |cu| cu.klass == klass }
31
+ by_group = checkups.group_by(&:group)
32
+ results = []
33
+
34
+ by_group.each do |group, group_checkups|
35
+ preconditions = group_checkups.select(&:precondition)
36
+ dependents = group_checkups.reject(&:precondition)
37
+
38
+ # run preconditions first
39
+ preconditions_passed = true
40
+ preconditions.each do |cu|
41
+ result = cu.check verbose: verbose, ignore_condition: ignore_condition
42
+ results << result if result
43
+ preconditions_passed = false unless cu.success?
44
+ end
45
+
46
+ # only run dependents if all preconditions passed
47
+ if preconditions_passed
48
+ dependents.each do |cu|
49
+ result = cu.check verbose: verbose, ignore_condition: ignore_condition
50
+ results << result if result
51
+ end
52
+ end
31
53
  end
54
+
55
+ results
32
56
  end
33
57
 
34
58
  def find_or_create_checkup_group name
@@ -91,8 +115,9 @@ module Hospital
91
115
  if !checkup.skipped && (!checkup.group.skipped || checkup.precondition)
92
116
  @out.put_diagnosis_header "#{diagnosis.name}:"
93
117
  diagnosis.put_results @out
94
- elsif verbose
95
- @out.put_diagnosis_skipped "Skipped #{diagnosis.name}."
118
+ elsif !checkup.skipped
119
+ # checkup was skipped due to group precondition failure
120
+ @out.put_diagnosis_skipped "#{diagnosis.name}:", verbose: verbose
96
121
  end
97
122
  end
98
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hospital
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander