Sha256: 6115134581e7ec34b3f71dfd49a8c457d47dbacf1b61fccd0def0957b87f14b8

Contents?: true

Size: 964 Bytes

Versions: 26

Compression:

Stored size: 964 Bytes

Contents

module VCR
  # Ruby 1.8 provides Ping.pingecho, but it was removed in 1.9.
  # So we try requiring it, and if that fails, define it ourselves.
  begin
    require 'ping'
    Ping = ::Ping
  rescue LoadError
    # This is copied, verbatim, from Ruby 1.8.7's ping.rb.
    require 'timeout'
    require "socket"

    # @private
    module Ping
      def pingecho(host, timeout=5, service="echo")
        begin
          timeout(timeout) do
            s = TCPSocket.new(host, service)
            s.close
          end
        rescue Errno::ECONNREFUSED
          return true
        rescue Timeout::Error, StandardError
          return false
        end
        return true
      end
      module_function :pingecho
    end
  end

  # @private
  module InternetConnection
    extend self

    EXAMPLE_HOST = "example.com"

    def available?
      @available = VCR::Ping.pingecho(EXAMPLE_HOST, 1, 80) unless defined?(@available)
      @available
    end
  end
end

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/vcr-2.9.3/lib/vcr/util/internet_connection.rb
vcr-3.0.1 lib/vcr/util/internet_connection.rb
vcr-3.0.0 lib/vcr/util/internet_connection.rb
mustwin-vcr-2.9.3 lib/vcr/util/internet_connection.rb
vcr-2.9.3 lib/vcr/util/internet_connection.rb
vcr-2.9.2 lib/vcr/util/internet_connection.rb
vcr-2.9.1 lib/vcr/util/internet_connection.rb
vcr-2.9.0 lib/vcr/util/internet_connection.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/vcr-2.8.0/lib/vcr/util/internet_connection.rb
vcr-2.8.0 lib/vcr/util/internet_connection.rb
vcr-2.7.0 lib/vcr/util/internet_connection.rb
vcr-2.6.0 lib/vcr/util/internet_connection.rb
vcr-2.5.0 lib/vcr/util/internet_connection.rb
vcr-2.4.0 lib/vcr/util/internet_connection.rb
vcr-2.3.0 lib/vcr/util/internet_connection.rb
vcr-2.2.5 lib/vcr/util/internet_connection.rb
vcr-2.2.4 lib/vcr/util/internet_connection.rb
vcr-2.2.3 lib/vcr/util/internet_connection.rb
vcr-2.2.2 lib/vcr/util/internet_connection.rb
vcr-2.2.1 lib/vcr/util/internet_connection.rb