Module: Chef::Mixin::Uris

Instance Method Summary collapse

Instance Method Details

#as_uri(source) ⇒ Object



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

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 foo.bar.com

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/chef/mixin/uris.rb', line 28

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