hospital 0.2.0 → 0.4.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: 4fe2ccd9fe0117efeaf99d430e269bee6e11e27463161d7038f4550ad79dcabb
4
+ data.tar.gz: 045b72881224032291189022ede2c9eec3aacc8edb52a688d05570e0ad54d871
5
5
  SHA512:
6
- metadata.gz: 870e3c40165b74923f4da76e54a58ec5ee2d32b7803d57eb59ce492d41b4686ec531f14af7726a264badb19db086c118e3fd80db9d7308201500b3e6d93a433f
7
- data.tar.gz: e0dd681f5d4bfdcab6ce3dcd4e741140b02182f93a6746990b12c2ad141085ae0974823672de4999090313876c5f9ed785e08353510336343dc0ae160e880302
6
+ metadata.gz: 7ead12b8b24f8aaae387ac81c400950f02d682260a136cecb5f97007e0607a89d55900ccd5e112f82d1137484295990042dfe0f98e91a570755b354ac08e2181
7
+ data.tar.gz: a269f71f8736c77172da1798f6f78623dccbcb887167193b7b0c998611786df554f5a035e66f2acf2dd6b292b6647caf7d0c822d2fed6301d68c85788c4322c6
@@ -0,0 +1,88 @@
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
+ success = true
18
+ if (missing_vars = env_vars.select{|var| ENV[var].nil? || ENV[var].empty? }).any?
19
+ add_error("These necessary ENV vars are not set: #{variable_list(missing_vars)}.")
20
+ success = false
21
+ else
22
+ add_info("All necessary ENV vars are set.")
23
+ end
24
+ end
25
+
26
+ def variable_list vars
27
+ "[#{vars.map{|v| "'#{v}'"}.join(', ')}]"
28
+ end
29
+
30
+ class Result
31
+ attr_reader :message, :prefix
32
+
33
+ def initialize message
34
+ @message = message
35
+ end
36
+
37
+ def output
38
+ "#{prefix} #{message.gsub(/\n\z/, '').gsub(/\n/, prefix ? "\n " : "\n")}"
39
+ end
40
+
41
+ def put
42
+ puts output
43
+ end
44
+ end
45
+
46
+ class Info < Result
47
+ def prefix; '🟢' end
48
+ end
49
+
50
+ class Warning < Result
51
+ def prefix; '🟠'; end
52
+ end
53
+
54
+ class Error < Result
55
+ def prefix; '🔴'; end
56
+ end
57
+
58
+ def add_info message
59
+ info = Info.new message
60
+ @infos << info
61
+ @results << info
62
+ end
63
+
64
+ def add_warning message
65
+ warning = Warning.new message
66
+ @warnings << warning
67
+ @results << warning
68
+ end
69
+
70
+ def add_error message
71
+ error = Error.new message
72
+ @errors << error
73
+ @results << error
74
+ end
75
+
76
+ def put_results
77
+ put_header "Checking #{name}:"
78
+ results.each &:put
79
+ end
80
+
81
+ private
82
+
83
+ def put_header message
84
+ puts ''
85
+ puts "### #{message}"
86
+ end
87
+
88
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../hospital'
4
+
5
+ desc 'Check system setup sanity.'
6
+ task :doctor => :environment do
7
+ # at_exit { Rake::Task['doctor:summary'].invoke if $!.nil? }
8
+
9
+ # silence warnings about double constant definitions
10
+ Kernel::silence_warnings do
11
+ Rails.application.eager_load!
12
+ end
13
+
14
+ Hospital.checkup_all
15
+ 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.4.0"
5
5
  end
data/lib/hospital.rb CHANGED
@@ -1,8 +1,50 @@
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
+
46
+ Summary:
47
+ Errors: #{errcount}
48
+ END
49
+ end
8
50
  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.4.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-21 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.1.6
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