Class: ChefCLI::Policyfile::SourceURI

Inherits:
Addressable::URI
  • Object
show all
Defined in:
lib/chef-cli/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) ⇒ ChefCLI::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:



37
38
39
40
41
42
43
# File 'lib/chef-cli/policyfile/source_uri.rb', line 37

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

Instance Method Details

#validateObject



49
50
51
52
53
54
55
56
57
# File 'lib/chef-cli/policyfile/source_uri.rb', line 49

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