Module: Beaker::DSL::Helpers::WebHelpers

Included in:
Beaker::DSL::Helpers
Defined in:
lib/beaker/dsl/helpers/web_helpers.rb

Overview

Convenience methods for checking links and moving web content to hosts

Instance Method Summary collapse

Instance Method Details

Determine is a given URL is accessible

Examples:

extension = link_exists?("#{URL}.tar.gz") ? ".tar.gz" : ".tar"

Parameters:

  • link (String)

    The URL to examine

Returns:

  • (Boolean)

    true if the URL has a '200' HTTP response code, false otherwise



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/beaker/dsl/helpers/web_helpers.rb', line 20

def link_exists?(link)
  require "net/http"
  require "net/https"
  require "open-uri"
  url = URI.parse(link)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = (url.scheme == 'https')
  http.verify_mode = (OpenSSL::SSL::VERIFY_NONE)
  http.start do |http|
    return http.head(url.request_uri).code == "200"
  end
end

#port_open_within?(host, port = 8140, seconds = 120) ⇒ Boolean

Blocks until the port is open on the host specified, returns false on failure

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/beaker/dsl/helpers/web_helpers.rb', line 9

def port_open_within?( host, port = 8140, seconds = 120 )
  repeat_for( seconds ) do
    host.port_open?( port )
  end
end