hospital 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hospital/checkup.rb +6 -2
- data/lib/hospital/checkup_group.rb +5 -3
- data/lib/hospital/diagnosis.rb +8 -6
- data/lib/hospital/formatter/base.rb +11 -0
- data/lib/hospital/formatter/pre.rb +31 -0
- data/lib/hospital/formatter/shell.rb +31 -0
- data/lib/hospital/{formatter.rb → string_formatter.rb} +1 -1
- data/lib/hospital/tasks/checkup.rake +5 -1
- data/lib/hospital/version.rb +1 -1
- data/lib/hospital.rb +52 -36
- metadata +6 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015cbd4e1cdf4fe514dae131d12ca4618f38f44794d32828f6142825df2b174c
|
4
|
+
data.tar.gz: 1e50476e5248f25d0035670e0e786afbf06c780c5d61789b841ad7a32c72470f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 045c39bff60f84dcb2dc691aa3a2892d902ca5270615721e91354ab60e327a4bca19412aeb508220787db60c867ea833175c155f270944e160e7dd69c5ec6f50
|
7
|
+
data.tar.gz: 19b21cf6489ac8cc2a192b96f39404f616cbeb00e82d401a33401b797afca657866b5721fae190b0f7653b09152e3b9680e91e9d7951082771b5b3547a42a007
|
data/lib/hospital/checkup.rb
CHANGED
@@ -4,13 +4,13 @@ module Hospital
|
|
4
4
|
class Checkup
|
5
5
|
attr_reader :code, :condition, :diagnosis, :group, :skipped, :klass, :precondition
|
6
6
|
|
7
|
-
def initialize klass, code,
|
7
|
+
def initialize klass, code, title: nil, condition: -> { true }, precondition: false
|
8
8
|
@klass = klass
|
9
9
|
@code = code
|
10
|
-
@group = group
|
11
10
|
@condition = condition
|
12
11
|
@diagnosis = Hospital::Diagnosis.new([klass.to_s, title].compact.join(' - '))
|
13
12
|
@precondition = precondition
|
13
|
+
@group = nil
|
14
14
|
end
|
15
15
|
|
16
16
|
def reset_diagnosis
|
@@ -35,5 +35,9 @@ module Hospital
|
|
35
35
|
def success?
|
36
36
|
diagnosis.success?
|
37
37
|
end
|
38
|
+
|
39
|
+
def set_group group
|
40
|
+
@group = group
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "string_formatter"
|
2
2
|
|
3
|
-
using
|
3
|
+
using StringFormatter
|
4
4
|
|
5
5
|
module Hospital
|
6
6
|
class CheckupGroup
|
@@ -18,10 +18,12 @@ module Hospital
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def header
|
21
|
-
"
|
21
|
+
"#{name.to_s.capitalize.gsub(/_/, ' ')} checks"
|
22
22
|
end
|
23
23
|
|
24
24
|
def add_checkup checkup
|
25
|
+
checkup.set_group self
|
26
|
+
|
25
27
|
if checkup.precondition
|
26
28
|
@precondition_checkups << checkup
|
27
29
|
else
|
data/lib/hospital/diagnosis.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "string_formatter"
|
2
2
|
|
3
|
-
using
|
3
|
+
using StringFormatter
|
4
4
|
|
5
5
|
class Hospital::Diagnosis
|
6
6
|
attr_reader :infos, :warnings, :skips, :errors, :name, :results
|
@@ -49,8 +49,8 @@ class Hospital::Diagnosis
|
|
49
49
|
"#{prefix} #{message.gsub(/\n\z/, '').gsub(/\n/, prefix ? "\n " : "\n")}"
|
50
50
|
end
|
51
51
|
|
52
|
-
def put
|
53
|
-
|
52
|
+
def put out
|
53
|
+
out.put_diagnosis_result output
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -94,8 +94,10 @@ class Hospital::Diagnosis
|
|
94
94
|
@results << error
|
95
95
|
end
|
96
96
|
|
97
|
-
def put_results
|
98
|
-
results.each
|
97
|
+
def put_results out
|
98
|
+
results.each do |result|
|
99
|
+
result.put out
|
100
|
+
end
|
99
101
|
end
|
100
102
|
|
101
103
|
def success?
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
using StringFormatter
|
4
|
+
|
5
|
+
module Hospital
|
6
|
+
module Formatter
|
7
|
+
class Pre < Base
|
8
|
+
def put_group_header text
|
9
|
+
@buffer << "\n\n### #{text}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def put_diagnosis_header text
|
13
|
+
@buffer << "\n\n## #{text}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def put_summary errors_count, warnings_count
|
17
|
+
@buffer << <<~END
|
18
|
+
\n\n
|
19
|
+
#### Summary:
|
20
|
+
Errors: #{errors_count}
|
21
|
+
Warnings: #{warnings_count}
|
22
|
+
END
|
23
|
+
end
|
24
|
+
|
25
|
+
def put_diagnosis_result text
|
26
|
+
@buffer << "\n#{text}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
using StringFormatter
|
4
|
+
|
5
|
+
module Hospital
|
6
|
+
module Formatter
|
7
|
+
class Shell < Base
|
8
|
+
def put_group_header text
|
9
|
+
@buffer << "\n### #{text}".h1
|
10
|
+
end
|
11
|
+
|
12
|
+
def put_diagnosis_header text
|
13
|
+
@buffer << "\n#{text.h2.indented}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def put_summary errors_count, warnings_count
|
17
|
+
@buffer << <<~END
|
18
|
+
|
19
|
+
#{"Summary:".h1}
|
20
|
+
#{"Errors: #{errors_count}".red}
|
21
|
+
#{"Warnings: #{warnings_count}".yellow}
|
22
|
+
END
|
23
|
+
end
|
24
|
+
|
25
|
+
def put_diagnosis_result text
|
26
|
+
@buffer << "\n#{text.indented}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative '../../hospital'
|
4
4
|
|
5
|
+
# usage:
|
6
|
+
# rake doctor
|
7
|
+
# rake doctor[true]
|
8
|
+
|
5
9
|
desc 'Check system setup sanity.'
|
6
10
|
task :doctor, [:verbose] => :environment do |t, args|
|
7
11
|
verbose = args[:verbose] == "true"
|
@@ -13,5 +17,5 @@ task :doctor, [:verbose] => :environment do |t, args|
|
|
13
17
|
end
|
14
18
|
|
15
19
|
p "start checkup" if verbose
|
16
|
-
Hospital.
|
20
|
+
puts Hospital::Runner.new(verbose: verbose).do_checkup_all
|
17
21
|
end
|
data/lib/hospital/version.rb
CHANGED
data/lib/hospital.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "byebug"
|
4
3
|
require_relative "hospital/version"
|
5
4
|
require_relative "hospital/checkup"
|
6
5
|
require_relative "hospital/checkup_group"
|
7
6
|
require_relative "hospital/diagnosis"
|
8
|
-
require_relative "hospital/
|
7
|
+
require_relative "hospital/string_formatter"
|
8
|
+
require_relative "hospital/formatter/shell"
|
9
|
+
require_relative "hospital/formatter/pre"
|
9
10
|
|
10
|
-
using
|
11
|
+
using StringFormatter
|
11
12
|
|
12
13
|
module Hospital
|
13
14
|
require_relative 'railtie' if defined?(Rails)
|
@@ -22,37 +23,6 @@ module Hospital
|
|
22
23
|
raise Hospital::Error.new("Cannot include Hospital, please extend instead.")
|
23
24
|
end
|
24
25
|
|
25
|
-
def do_checkup_all verbose: false
|
26
|
-
errcount = 0
|
27
|
-
warcount = 0
|
28
|
-
|
29
|
-
@@groups.each do |group|
|
30
|
-
puts group.header
|
31
|
-
group.run_checkups verbose: verbose
|
32
|
-
|
33
|
-
group.all_checkups.each do |checkup|
|
34
|
-
if diagnosis = checkup.diagnosis
|
35
|
-
errcount += diagnosis.errors.count
|
36
|
-
warcount += diagnosis.warnings.count
|
37
|
-
|
38
|
-
if !checkup.skipped
|
39
|
-
puts "Checking #{diagnosis.name}:".h2.indented
|
40
|
-
diagnosis.put_results
|
41
|
-
elsif verbose
|
42
|
-
puts "Skipped #{diagnosis.name}.".h2.indented
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
puts <<~END
|
49
|
-
|
50
|
-
#{"Summary:".h1}
|
51
|
-
#{"Errors: #{errcount}".red}
|
52
|
-
#{"Warnings: #{warcount}".yellow}
|
53
|
-
END
|
54
|
-
end
|
55
|
-
|
56
26
|
# used to call the checkup for a specific class directly (in specs)
|
57
27
|
def do_checkup(klass, verbose: false)
|
58
28
|
@@groups.map(&:all_checkups).flatten.select{|cu| cu.klass == klass }.map do |cu|
|
@@ -67,6 +37,10 @@ module Hospital
|
|
67
37
|
end
|
68
38
|
checkup_group
|
69
39
|
end
|
40
|
+
|
41
|
+
def groups
|
42
|
+
@@groups
|
43
|
+
end
|
70
44
|
end
|
71
45
|
|
72
46
|
def checkup if: -> { true }, group: :general, title: nil, precondition: false, &code
|
@@ -74,13 +48,55 @@ module Hospital
|
|
74
48
|
checkup = Checkup.new(
|
75
49
|
self,
|
76
50
|
code,
|
77
|
-
group: group,
|
78
51
|
title: title,
|
79
52
|
condition: binding.local_variable_get('if'),
|
80
53
|
precondition: precondition
|
81
54
|
)
|
82
55
|
|
83
|
-
# p "adding #{checkup.inspect} to #{
|
56
|
+
# p "adding #{checkup.inspect} to #{group_name}"
|
84
57
|
checkup_group.add_checkup checkup
|
85
58
|
end
|
59
|
+
|
60
|
+
class Runner
|
61
|
+
attr_reader :verbose
|
62
|
+
|
63
|
+
def initialize verbose: false, formatter: :shell
|
64
|
+
@verbose = verbose
|
65
|
+
@formatter = case formatter
|
66
|
+
when :pre then Formatter::Pre
|
67
|
+
else Formatter::Shell
|
68
|
+
end
|
69
|
+
|
70
|
+
@out = @formatter.new
|
71
|
+
# @out.put_group_header "using formatter #{@formatter}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def do_checkup_all
|
75
|
+
errcount = 0
|
76
|
+
warcount = 0
|
77
|
+
|
78
|
+
Hospital.groups.each do |group|
|
79
|
+
@out.put_group_header group.header
|
80
|
+
group.run_checkups verbose: verbose
|
81
|
+
|
82
|
+
group.all_checkups.each do |checkup|
|
83
|
+
if diagnosis = checkup.diagnosis
|
84
|
+
errcount += diagnosis.errors.count
|
85
|
+
warcount += diagnosis.warnings.count
|
86
|
+
|
87
|
+
if !checkup.skipped && (!checkup.group.skipped || checkup.precondition)
|
88
|
+
@out.put_diagnosis_header "Checking #{diagnosis.name}:"
|
89
|
+
diagnosis.put_results @out
|
90
|
+
elsif verbose
|
91
|
+
@out.put_diagnosis_header "Skipped #{diagnosis.name}."
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
@out.put_summary errcount, warcount
|
98
|
+
|
99
|
+
@out.buffer
|
100
|
+
end
|
101
|
+
end
|
86
102
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hospital
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: byebug
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: require_all
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +38,10 @@ files:
|
|
52
38
|
- lib/hospital/checkup.rb
|
53
39
|
- lib/hospital/checkup_group.rb
|
54
40
|
- lib/hospital/diagnosis.rb
|
55
|
-
- lib/hospital/formatter.rb
|
41
|
+
- lib/hospital/formatter/base.rb
|
42
|
+
- lib/hospital/formatter/pre.rb
|
43
|
+
- lib/hospital/formatter/shell.rb
|
44
|
+
- lib/hospital/string_formatter.rb
|
56
45
|
- lib/hospital/tasks/checkup.rake
|
57
46
|
- lib/hospital/version.rb
|
58
47
|
- lib/railtie.rb
|