Module: FailFast::CheckUrl

Defined in:
lib/fail_fast/extensions/check_url.rb

Instance Method Summary collapse

Instance Method Details

#has_url_for(key, *params) ⇒ Object

Usage

test if the url is valid :
  has_url_for 'test/server_url'
test if the url is reachable :
  has_url_for 'test/server_url', :reachable => true
test if the url is reachable, possibly after adding a trailing slash.
(ex: http://example.com  + http://example.com/)
  has_url_for 'test/server_url', :reachable => true, :may_add_trailing_slash => true


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fail_fast/extensions/check_url.rb', line 13

def has_url_for(key, *params)
  p = key_value_regexp_options(key, params)
  key, options = p.key, p.options
  return unless has_value_for key, :message =>  options[:message]

  value = value_for_deep_key(key)
  if UrlValidator.invalid_url?(value)
    add_error ErrorDetails.new(key, :not_a_url, value, options[:message])
    return
  end
  if true==options.delete(:reachable) && UrlValidator.unreachable_url?(value, options)
    add_error ErrorDetails.new(key, :url_not_reachable, value, options[:message])
  end
end