Sha256: e65b78fbdb0d39fc37b06842b34fd767b315b0fdde5bce7117da64df3ef0f9b0

Contents?: true

Size: 682 Bytes

Versions: 13

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

require "uri"

module Hanami
  module CLI
    module URL
      DEFAULT_URL_PREFIX = "/"
      private_constant :DEFAULT_URL_PREFIX

      class << self
        def call(url)
          result = url
          result = URI.parse(result).path

          unless valid?(result)
            raise ArgumentError.new("invalid URL: `#{url}'")
          end

          result
        rescue URI::InvalidURIError
          raise ArgumentError.new("invalid URL: `#{url}'")
        end
        alias_method :[], :call

        def valid?(url)
          return false if url.nil?

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hanami-cli-2.0.0.rc1 lib/hanami/cli/url.rb
hanami-cli-2.0.0.beta4 lib/hanami/cli/url.rb
hanami-cli-2.0.0.beta3 lib/hanami/cli/url.rb
hanami-cli-2.0.0.beta2 lib/hanami/cli/url.rb
hanami-cli-2.0.0.beta1 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha8.1 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha8 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha7 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha6.1 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha6 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha4 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha3 lib/hanami/cli/url.rb
hanami-cli-2.0.0.alpha2 lib/hanami/cli/url.rb