Class: ChefDK::Policyfile::SourceURI

Inherits:
Addressable::URI
  • Object
show all
Defined in:
lib/chef-dk/policyfile/source_uri.rb

Constant Summary collapse

VALID_SCHEMES =
%w{ https http }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(uri) ⇒ ChefDK::Policyfile::SourceURI

Returns a URI object based on the parsed string.

string to parse. No parsing is performed if the object is already an Addressable::URI.

Parameters:

  • uri (String, Addressable::URI, #to_str)

    The URI

Returns:

Raises:



34
35
36
37
38
39
40
# File 'lib/chef-dk/policyfile/source_uri.rb', line 34

def parse(uri)
  parsed_uri = super(uri)
  parsed_uri.send(:validate)
  parsed_uri
rescue TypeError, ArgumentError => ex
  raise ChefDK::InvalidPolicyfileSourceURI.new(uri, ex)
end

Instance Method Details

#validateObject



46
47
48
49
50
51
52
53
54
# File 'lib/chef-dk/policyfile/source_uri.rb', line 46

def validate
  super

  unless VALID_SCHEMES.include?(scheme)
    raise InvalidPolicyfileSourceURI.new(self, "invalid URI scheme '#{scheme}'. Valid schemes: #{VALID_SCHEMES}")
  end
rescue Addressable::URI::InvalidURIError => ex
  raise InvalidPolicyfileSourceURI.new(self, ex)
end