Sha256: a91d0d9d7bb4dd8ef049e0ef26dce94e8322d7d60b70a1b5228f02505bdfbb2a

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'uri/query_params/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 2.2.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/v2_2_0/lib/uri/generic.rb#L1338-L1376
    #
    def to_s
      str = ''
      if @scheme
        str << @scheme
        str << ':'.freeze
      end

      if @opaque
        str << @opaque
      else
        if @host
          str << '//'.freeze
        end
        if self.userinfo
          str << self.userinfo
          str << '@'.freeze
        end
        if @host
          str << @host
        end
        if @port && @port != self.default_port
          str << ':'.freeze
          str << @port.to_s
        end
        str << @path
        if query
          str << '?'.freeze
          str << query
        end
      end
      if @fragment
        str << '#'.freeze
        str << @fragment
      end
      str
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uri-query_params-0.8.0 lib/uri/query_params/core_ext/uri/generic.rb
uri-query_params-0.7.2 lib/uri/query_params/extensions/uri/generic.rb
uri-query_params-0.7.1 lib/uri/query_params/extensions/uri/generic.rb