Module: Chef::Mixin::Uris

Instance Method Summary collapse

Instance Method Details

#as_uri(source) ⇒ Object



35
36
37
38
39
40
# File 'lib/chef/mixin/uris.rb', line 35

def as_uri(source)
  URI.parse(source)
rescue URI::InvalidURIError
  Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters")
  URI.parse(Addressable::URI.encode(source))
end

#uri_scheme?(source) ⇒ Boolean

uri_scheme? returns true if the string starts with scheme:// For example, it will match http://foo.bar.com

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/chef/mixin/uris.rb', line 30

def uri_scheme?(source)
  # From open-uri
  !!(%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ source)
end