hospital 0.8.2 → 0.8.3

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: bfcbe599829bcaf2c9cb197b398f44a6571d9ab67cc50ccb0b17e35c0ee7a490
4
+ data.tar.gz: de51adaacd2978a830f793346d27bebd563ed200dcc6e8e9739fe9d1695dae51
5
5
  SHA512:
6
- metadata.gz: 37f5f27286a859bdcb4c54f380ac3f9af6cd9b907310f4434e340ab3e4bce388bcb5369ddfe2f191b5612a5bdc57bbcd9659bbbea5ddcd01d7b8566d055ce3dd
7
- data.tar.gz: 75c6a04304725ebe87adcfff3239d563b7a1a01b04d8af784c127ed68c259d5af609f8a417dfae54a85af38a7dcc9021fb1bfa5733a2e7516c3f8358998e9d73
6
+ metadata.gz: 6573587d48ee9f18fbd9f4993db20872fcecff2b35533af8c0a70137b8038b4aceba4a486864c16114350ae089a4cc6e712eddc16fb50a8dcc0fd1ac8dfa0fc8
7
+ data.tar.gz: cb776fcc3cce26a735e110e180900b4d137c649402d619f90f88cfcce641c1118ef937ae5cccdacf8b27bbb80e9d8318a7a41fa42f531ec80e8c4a5ed2737d1d
@@ -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.3"
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
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander