Sha256: ba16febb956aebf2173c5256301cebbb3da5439b5e13161de79d9464c184973c

Contents?: true

Size: 802 Bytes

Versions: 12

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true

require "uri"
require_relative "errors"

module Hanami
  module CLI
    # @since 2.0.0
    # @api private
    module URL
      DEFAULT_URL_PREFIX = "/"
      private_constant :DEFAULT_URL_PREFIX

      class << self
        # @since 2.0.0
        # @api private
        def call(url)
          result = url
          result = URI.parse(result).path

          unless valid?(result)
            raise InvalidURLError.new(url)
          end

          result
        rescue URI::InvalidURIError
          raise InvalidURLError.new(url)
        end
        alias_method :[], :call

        # @since 2.0.0
        # @api private
        def valid?(url)
          return false if url.nil?

          url.start_with?(DEFAULT_URL_PREFIX)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hanami-cli-2.2.1 lib/hanami/cli/url.rb
hanami-cli-2.2.0 lib/hanami/cli/url.rb
hanami-cli-2.2.0.rc1 lib/hanami/cli/url.rb
hanami-cli-2.2.0.beta2 lib/hanami/cli/url.rb
hanami-cli-2.2.0.beta1 lib/hanami/cli/url.rb
hanami-cli-2.1.1 lib/hanami/cli/url.rb
hanami-cli-2.1.0 lib/hanami/cli/url.rb
hanami-cli-2.1.0.rc3 lib/hanami/cli/url.rb
hanami-cli-2.1.0.rc2 lib/hanami/cli/url.rb
hanami-cli-2.1.0.rc1 lib/hanami/cli/url.rb
hanami-cli-2.1.0.beta2 lib/hanami/cli/url.rb
hanami-cli-2.1.0.beta1 lib/hanami/cli/url.rb