Class: GitHubPages::HealthCheck::Printer
- Inherits:
-
Object
- Object
- GitHubPages::HealthCheck::Printer
- Defined in:
- lib/github-pages-health-check/printer.rb
Constant Summary collapse
- PRETTY_LEFT_WIDTH =
11
- PRETTY_JOINER =
" | "
Instance Attribute Summary collapse
-
#health_check ⇒ Object
readonly
Returns the value of attribute health_check.
Instance Method Summary collapse
-
#initialize(health_check) ⇒ Printer
constructor
A new instance of Printer.
- #ljust(line) ⇒ Object
- #new_line(left = nil, right = nil) ⇒ Object
- #pretty_print ⇒ Object
- #simple_string ⇒ Object
Constructor Details
#initialize(health_check) ⇒ Printer
Returns a new instance of Printer.
9 10 11 |
# File 'lib/github-pages-health-check/printer.rb', line 9 def initialize(health_check) @health_check = health_check end |
Instance Attribute Details
#health_check ⇒ Object (readonly)
Returns the value of attribute health_check.
7 8 9 |
# File 'lib/github-pages-health-check/printer.rb', line 7 def health_check @health_check end |
Instance Method Details
#ljust(line) ⇒ Object
68 69 70 |
# File 'lib/github-pages-health-check/printer.rb', line 68 def ljust(line) line.ljust(PRETTY_LEFT_WIDTH) end |
#new_line(left = nil, right = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/github-pages-health-check/printer.rb', line 58 def new_line(left = nil, right = nil) if left and right ljust(left) + PRETTY_JOINER + right elsif left ljust(left) elsif right " " * (PRETTY_LEFT_WIDTH + PRETTY_JOINER.size) + right end end |
#pretty_print ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/github-pages-health-check/printer.rb', line 20 def pretty_print values = health_check.to_hash output = StringIO.new # Header output.puts new_line "Domain", "#{values[:uri]}" output.puts ("-" * (PRETTY_LEFT_WIDTH + 1)) + "|" + "-" * 50 output.puts new_line "DNS", "does not resolve" if not values[:dns_resolves?] # Valid? output.write new_line "State", "#{values[:valid?] ? "valid" : "invalid"}" output.puts " - is #{"NOT " if not values[:served_by_pages?]}served by Pages" # What's wrong? output.puts new_line "Reason", "#{values[:reason]}" if not values[:valid?] output.puts new_line nil, "pointed to user domain" if values[:pointed_to_github_user_domain?] output.puts new_line nil, "pointed to pages IP" if values[:pointed_to_github_pages_ip?] # DNS Record info output.write new_line "Record Type", "#{values[:a_record?] ? "A" : values[:cname_record?] ? "CNAME" : "other"}" output.puts values[:should_be_a_record?] ? ", should be A record" : ", should be CNAME" ip_problems = [] ip_problems << "not apex domain" if not values[:apex_domain?] ip_problems << "invalid domain" if not values[:valid_domain?] ip_problems << "old ip address used" if values[:old_ip_address?] output.puts new_line "IP Problems", "#{ip_problems.size > 0 ? ip_problems.join(", ") : "none"} " if values[:proxied?] output.puts new_line "Proxied", "yes, through #{values[:cloudflare_ip?] ? "CloudFlare" : "unknown"}" end output.puts new_line "Domain", "*.github.com/io domain" if values[:pages_domain?] output.string end |
#simple_string ⇒ Object
13 14 15 16 17 18 |
# File 'lib/github-pages-health-check/printer.rb', line 13 def simple_string require 'yaml' hash = health_check.to_hash hash[:reason] = hash[:reason].to_s if hash[:reason] hash.to_yaml.sub(/\A---\n/, "").gsub(/^:/, "") end |