hospital 0.2.0 → 0.3.0

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: 6f8da0744448857dbd214916e8a2767f17c1ffa2fac62ebee528c9b6fdd045ea
4
- data.tar.gz: ac90c8b38035d8dee4f968161148042e41b774ad574b311a63ee480b82d896e1
3
+ metadata.gz: b1df079afc135900573cf9a989a01d9dbc1ef917ead9e5f6898ea3faa94c0523
4
+ data.tar.gz: 0e82ab36be7b2dd80f6ec6212d62074d48746ad54710e6aff78da0e630878fe1
5
5
  SHA512:
6
- metadata.gz: 870e3c40165b74923f4da76e54a58ec5ee2d32b7803d57eb59ce492d41b4686ec531f14af7726a264badb19db086c118e3fd80db9d7308201500b3e6d93a433f
7
- data.tar.gz: e0dd681f5d4bfdcab6ce3dcd4e741140b02182f93a6746990b12c2ad141085ae0974823672de4999090313876c5f9ed785e08353510336343dc0ae160e880302
6
+ metadata.gz: 4b0a6363c4f08c17514ef1557e7aefe59abb9b04beb2b961c43db1ea9faef80265cbb32e66c5f15fb887632402dfd698b7d74f197a33531122b1b5ab0d229538
7
+ data.tar.gz: d441ee4bd337d0820373a19f0f079624d3fc9f62a56d69b6f3211039424bd66187934a885bf1650c3038aef0a4b328fe967300082ff3bd6f49f04a816e221661
@@ -0,0 +1,86 @@
1
+ class Hospital::Diagnosis
2
+ attr_reader :infos, :warnings, :errors, :name, :results
3
+
4
+ def initialize name
5
+ @name = name.to_s
6
+ reset
7
+ end
8
+
9
+ def reset
10
+ @infos = []
11
+ @warnings = []
12
+ @errors = []
13
+ @results = []
14
+ end
15
+
16
+ def require_env_vars env_vars=[]
17
+ if (missing_vars = env_vars.select{|var| ENV[var].nil? || ENV[var].empty? }).any?
18
+ add_error("These necessary ENV vars are not set: #{variable_list(missing_vars)}.")
19
+ else
20
+ add_info("All necessary ENV vars are set.")
21
+ end
22
+ end
23
+
24
+ def variable_list vars
25
+ "[#{vars.map{|v| "'#{v}'"}.join(', ')}]"
26
+ end
27
+
28
+ class Result
29
+ attr_reader :message, :prefix
30
+
31
+ def initialize message
32
+ @message = message
33
+ end
34
+
35
+ def output
36
+ "#{prefix} #{message.gsub(/\n\z/, '').gsub(/\n/, prefix ? "\n " : "\n")}"
37
+ end
38
+
39
+ def put
40
+ puts output
41
+ end
42
+ end
43
+
44
+ class Info < Result
45
+ def prefix; '🟢' end
46
+ end
47
+
48
+ class Warning < Result
49
+ def prefix; '🟠'; end
50
+ end
51
+
52
+ class Error < Result
53
+ def prefix; '🔴'; end
54
+ end
55
+
56
+ def add_info message
57
+ info = Info.new message
58
+ @infos << info
59
+ @results << info
60
+ end
61
+
62
+ def add_warning message
63
+ warning = Warning.new message
64
+ @warnings << warning
65
+ @results << warning
66
+ end
67
+
68
+ def add_error message
69
+ error = Error.new message
70
+ @errors << error
71
+ @results << error
72
+ end
73
+
74
+ def put_results
75
+ put_header "Checking #{name}:"
76
+ results.each &:put
77
+ end
78
+
79
+ private
80
+
81
+ def put_header message
82
+ puts ''
83
+ puts "### #{message}"
84
+ end
85
+
86
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../hospital'
4
+
5
+ desc 'Check system setup sanity.'
6
+ task :doctor => [] do
7
+ # at_exit { Rake::Task['doctor:summary'].invoke if $!.nil? }
8
+
9
+ Hospital.checkup_all
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hospital
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/hospital.rb CHANGED
@@ -1,8 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "hospital/version"
4
+ require_relative "hospital/diagnosis"
4
5
 
5
6
  module Hospital
7
+ require_relative 'railtie' if defined?(Rails)
8
+
6
9
  class Error < StandardError; end
7
- # Your code goes here...
10
+
11
+ @@checkups = {}
12
+ @@diagnosises = {}
13
+
14
+ def self.included(base)
15
+ raise Hospital::Error.new("Cannot include Hospital, please extend instead.")
16
+ end
17
+
18
+ def self.extended(base)
19
+ @@checkups[base] = ->(diagnosis) do
20
+ diagnosis.add_warning("#{base}: No checks defined! Please call checkup with a lambda.")
21
+ end
22
+ @@diagnosises[base] = Hospital::Diagnosis.new(base)
23
+ end
24
+
25
+ def checkup code
26
+ @@checkups[self] = code
27
+ end
28
+
29
+ def self.checkup klass
30
+ @@diagnosises[klass].reset
31
+ @@checkups[klass].call(@@diagnosises[klass])
32
+ @@diagnosises[klass]
33
+ end
34
+
35
+ def self.checkup_all
36
+ errcount = 0
37
+ @@checkups.keys.each do |klass|
38
+ checkup(klass)
39
+ diagnosis = @@diagnosises[klass]
40
+ diagnosis.put_results
41
+ errcount += diagnosis.errors.count
42
+ end
43
+
44
+ puts <<~END
45
+ Summary:"
46
+ Errors: #{errcount}
47
+ END
48
+ end
8
49
  end
data/lib/railtie.rb ADDED
@@ -0,0 +1,14 @@
1
+ # lib/railtie.rb
2
+ require 'hospital'
3
+ require 'rails'
4
+
5
+ module Hospital
6
+ class Railtie < Rails::Railtie
7
+ railtie_name :hospital
8
+
9
+ rake_tasks do
10
+ path = File.expand_path(__dir__)
11
+ Dir.glob("#{path}/hospital/tasks/*.rake").each { |f| load f }
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hospital
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Imagine a team of little doctors creating diagnoses and creating a useful
14
14
  report.
@@ -18,17 +18,13 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".rspec"
22
- - CHANGELOG.md
23
- - CODE_OF_CONDUCT.md
24
- - Gemfile
25
21
  - LICENSE.txt
26
22
  - README.md
27
- - Rakefile
28
- - hospital.gemspec
29
23
  - lib/hospital.rb
24
+ - lib/hospital/diagnosis.rb
25
+ - lib/hospital/tasks/checkup.rake
30
26
  - lib/hospital/version.rb
31
- - sig/hospital.rbs
27
+ - lib/railtie.rb
32
28
  homepage: https://github.com/giantmonkey/hospital
33
29
  licenses:
34
30
  - MIT
@@ -44,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
40
  requirements:
45
41
  - - ">="
46
42
  - !ruby/object:Gem::Version
47
- version: 2.6.0
43
+ version: 2.7.8
48
44
  required_rubygems_version: !ruby/object:Gem::Requirement
49
45
  requirements:
50
46
  - - ">="
51
47
  - !ruby/object:Gem::Version
52
48
  version: '0'
53
49
  requirements: []
54
- rubygems_version: 3.2.33
50
+ rubygems_version: 3.2.32
55
51
  signing_key:
56
52
  specification_version: 4
57
53
  summary: A framwork for app self-checks
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2023-04-05
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at alexander@presber.net. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in hospital.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/hospital.gemspec DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/hospital/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "hospital"
7
- spec.version = Hospital::VERSION
8
- spec.authors = ["Alexander"]
9
- spec.email = ["alexander@presber.net"]
10
-
11
- spec.summary = "A framwork for app self-checks"
12
- spec.description = "Imagine a team of little doctors creating diagnoses and creating a useful report."
13
- spec.homepage = "https://github.com/giantmonkey/hospital"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "'https://rubygems.org'"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/giantmonkey/hospital"
21
- spec.metadata["changelog_uri"] = "https://github.com/giantmonkey/hospital/blob/main/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
36
-
37
- # For more information and examples about making a new gem, check out our
38
- # guide at: https://bundler.io/guides/creating_gem.html
39
- end
data/sig/hospital.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Hospital
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end