Sha256: 1e1d20305f9316424ed49cb448679da0ee32cdea13002cdda586f7d359ebca8d
Contents?: true
Size: 1.04 KB
Versions: 2
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true module Jekyll module Utils module Internet # Public: Determine whether the present device has a connection to # the Internet. This allows plugin writers which require the outside # world to have a neat fallback mechanism for offline building. # # Example: # if Internet.connected? # Typhoeus.get("https://pages.github.com/versions.json") # else # Jekyll.logger.warn "Warning:", "Version check has been disabled." # Jekyll.logger.warn "", "Connect to the Internet to enable it." # nil # end # # Returns true if a DNS call can successfully be made, or false if not. module_function def connected? !dns("example.com").nil? end def dns(domain) require "resolv" Resolv::DNS.open do |resolver| resolver.getaddress(domain) end rescue Resolv::ResolvError, Resolv::ResolvTimeout nil end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
jekyll-4.2.1 | lib/jekyll/utils/internet.rb |
ngage-0.0.0 | lib/ngage/jekyll/utils/internet.rb |