-
Notifications
You must be signed in to change notification settings - Fork 43
Add #pretty_print which prints a nice table of data #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7aa9700
Add #pretty_print which prints a nice table of data
parkr 5055b34
Merge branch 'master' into better-printer
benbalter 963e6fc
Use the old method for #to_s in Printer#simple_string
parkr 897cf50
reduce duplication in output
parkr e36ec9b
Require yaml as needed
parkr 0c729ec
Remove require 'json' from readme as it'll be added to code
parkr 4ae077c
Add require 'json' where needed
parkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class GitHubPages | ||
class HealthCheck | ||
class Printer | ||
PRETTY_LEFT_WIDTH = 11 | ||
PRETTY_JOINER = " | " | ||
|
||
attr_reader :health_check | ||
|
||
def initialize(health_check) | ||
@health_check = health_check | ||
end | ||
|
||
def simple_string | ||
health_check.to_hash.inject(Array.new) do |all, pair| | ||
all.push pair.join(": ") | ||
end.join("\n") | ||
end | ||
|
||
def pretty_print | ||
values = health_check.to_hash | ||
output = StringIO.new | ||
|
||
# Header | ||
output.puts new_line "Domain", "#{values[:uri]} was health checked" | ||
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 | ||
|
||
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 | ||
|
||
def ljust(line) | ||
line.ljust(PRETTY_LEFT_WIDTH) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this only be printed if
:should_be_a_record?
is true? Or always print it?