Sha256: 40bb26e8f1d3877123ac47ffc7fedbc5738192189edc6e8f84839aa22f14abb5

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require_relative '../../mixin'

require 'uri/generic'

module URI
  class Generic

    include URI::QueryParams::Mixin

    #
    # Constructs String from URI
    #
    # @note
    #   This is the `URI::Generic#to_s` method from Ruby 3.0.0, with the minor
    #   modification of calling the `query` method overrode by
    #   {URI::QueryParams::Mixin}, instead of `@query`.
    #
    # @see https://github.com/ruby/ruby/blob/v3_0.0/lib/uri/generic.rb#L1330-L1368
    #
    def to_s
      str = ''.dup
      if @scheme
        str << @scheme
        str << ':'
      end

      if @opaque
        str << @opaque
      else
        if @host || %w[file postgres].include?(@scheme)
          str << '//'
        end
        if self.userinfo
          str << self.userinfo
          str << '@'
        end
        if @host
          str << @host
        end
        if @port && @port != self.default_port
          str << ':'
          str << @port.to_s
        end
        str << @path
        if (query = self.query)
          str << '?'
          str << query
        end
      end
      if @fragment
        str << '#'
        str << @fragment
      end
      str
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uri-query_params-0.8.2 lib/uri/query_params/core_ext/uri/generic.rb