Sha256: 9305a0b8721d99f2fdd847201a92a1666e4c417ca3cb57b3198dce41f26f213a

Contents?: true

Size: 1.04 KB

Versions: 21

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

      private
      module_function
      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

21 entries across 21 versions & 1 rubygems

Version Path
jekyll-3.10.0 lib/jekyll/utils/internet.rb
jekyll-3.9.5 lib/jekyll/utils/internet.rb
jekyll-3.9.4 lib/jekyll/utils/internet.rb
jekyll-3.9.3 lib/jekyll/utils/internet.rb
jekyll-3.9.2 lib/jekyll/utils/internet.rb
jekyll-3.9.1 lib/jekyll/utils/internet.rb
jekyll-3.9.0 lib/jekyll/utils/internet.rb
jekyll-3.8.7 lib/jekyll/utils/internet.rb
jekyll-3.8.6 lib/jekyll/utils/internet.rb
jekyll-3.8.5 lib/jekyll/utils/internet.rb
jekyll-3.8.4 lib/jekyll/utils/internet.rb
jekyll-3.7.4 lib/jekyll/utils/internet.rb
jekyll-3.8.3 lib/jekyll/utils/internet.rb
jekyll-3.8.2 lib/jekyll/utils/internet.rb
jekyll-3.8.1 lib/jekyll/utils/internet.rb
jekyll-3.8.0 lib/jekyll/utils/internet.rb
jekyll-3.8.0.pre.rc2 lib/jekyll/utils/internet.rb
jekyll-3.8.0.pre.rc1 lib/jekyll/utils/internet.rb
jekyll-3.7.3 lib/jekyll/utils/internet.rb
jekyll-3.7.2 lib/jekyll/utils/internet.rb