Sha256: c65c5e6e35fea7b19babac906f4009a300f9945df2329b3c0482ab75531d9b5d

Contents?: true

Size: 1.04 KB

Versions: 21

Compression:

Stored size: 1.04 KB

Contents

require "addressable/uri"

module Berkshelf
  class SourceURI < Addressable::URI
    class << self
      # Returns a URI object based on the parsed string.
      #
      # @param [String, Addressable::URI, #to_str] uri
      #   The URI string to parse.
      #   No parsing is performed if the object is already an
      #   <code>Addressable::URI</code>.
      #
      # @raise [Berkshelf::InvalidSourceURI]
      #
      # @return [Berkshelf::SourceURI]
      def parse(uri)
        parsed_uri = super(uri)
        parsed_uri.send(:validate)
        parsed_uri
      rescue TypeError, ArgumentError => ex
        raise InvalidSourceURI.new(uri, ex)
      end
    end

    VALID_SCHEMES = %w{http https file}.freeze

    # @raise [Berkshelf::InvalidSourceURI]
    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
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
berkshelf-7.1.0 lib/berkshelf/source_uri.rb
berkshelf-7.0.10 lib/berkshelf/source_uri.rb
berkshelf-7.0.9 lib/berkshelf/source_uri.rb
berkshelf-7.0.8 lib/berkshelf/source_uri.rb
berkshelf-7.0.7 lib/berkshelf/source_uri.rb
berkshelf-6.3.4 lib/berkshelf/source_uri.rb
berkshelf-7.0.6 lib/berkshelf/source_uri.rb
berkshelf-7.0.5 lib/berkshelf/source_uri.rb
berkshelf-6.3.3 lib/berkshelf/source_uri.rb
berkshelf-7.0.4 lib/berkshelf/source_uri.rb
berkshelf-7.0.3 lib/berkshelf/source_uri.rb
berkshelf-7.0.2 lib/berkshelf/source_uri.rb
berkshelf-7.0.1 lib/berkshelf/source_uri.rb
berkshelf-7.0.0 lib/berkshelf/source_uri.rb
berkshelf-6.3.2 lib/berkshelf/source_uri.rb
berkshelf-6.3.1 lib/berkshelf/source_uri.rb
berkshelf-6.3.0 lib/berkshelf/source_uri.rb
berkshelf-6.2.2 lib/berkshelf/source_uri.rb
berkshelf-6.2.1 lib/berkshelf/source_uri.rb
berkshelf-6.2.0 lib/berkshelf/source_uri.rb