Skip to content

Memoize falsy values #30

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 2 commits into from
Sep 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/github-pages-health-check.rb
Original file line number Diff line number Diff line change
@@ -70,13 +70,19 @@ def proxied?

# Returns an array of DNS answers
def dns
@dns ||= Timeout::timeout(TIMEOUT) do
without_warnings do
Net::DNS::Resolver.start(absolute_domain).answer if domain
if @dns.nil?
begin
@dns = Timeout::timeout(TIMEOUT) do
without_warnings do
Net::DNS::Resolver.start(absolute_domain).answer if domain
end
end
@dns ||= false
rescue Exception
@dns = false
end
end
rescue Exception
nil
@dns || nil
end

# Are we even able to get the DNS record?
@@ -165,16 +171,17 @@ def to_hash
alias_method :to_h, :to_hash

def served_by_pages?
@served_by_pages ||= begin
if @served_by_pages.nil?
response = Typhoeus.head(uri, TYPHOEUS_OPTIONS)
# Workaround for webmock not playing nicely with Typhoeus redirects
# See https://github.com/bblimke/webmock/issues/237
if response.mock? && response.headers["Location"]
response = Typhoeus.head(response.headers["Location"], TYPHOEUS_OPTIONS)
end

(response.mock? || response.return_code == :ok) && response.headers["Server"] == "GitHub.com"
@served_by_pages = (response.mock? || response.return_code == :ok) && response.headers["Server"] == "GitHub.com"
end
@served_by_pages
end

def to_json