Class: Berkshelf::SourceURI

Inherits:
Addressable::URI
  • Object
show all
Defined in:
lib/berkshelf/source_uri.rb

Constant Summary collapse

VALID_SCHEMES =
%w{http https file}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(uri) ⇒ Berkshelf::SourceURI

Returns a URI object based on the parsed string.

Parameters:

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

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

Returns:

Raises:



16
17
18
19
20
21
22
# File 'lib/berkshelf/source_uri.rb', line 16

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

Instance Method Details

#validateObject



28
29
30
31
32
33
34
35
36
# File 'lib/berkshelf/source_uri.rb', line 28

def validate
  super

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