Class: URI::Generic

Inherits:
Object
  • Object
show all
Includes:
QueryParams::Mixin
Defined in:
lib/uri/query_params/core_ext/uri/generic.rb

Direct Known Subclasses

HTTP

Instance Attribute Summary

Attributes included from QueryParams::Mixin

#query_params

Instance Method Summary collapse

Methods included from QueryParams::Mixin

#each_query_param, included, #initialize_copy

Instance Method Details

#to_sObject

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 QueryParams::Mixin, instead of @query.

Constructs String from URI



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uri/query_params/core_ext/uri/generic.rb', line 22

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