Module: DR::URI::URIHelpers
- Included in:
- Wrapper
- Defined in:
- lib/dr/base/uri.rb
Instance Method Summary collapse
-
#reverse_merge(u2) ⇒ Object
uri=u2.merge(uri) does not work if uri is absolute.
-
#soft_merge(u2) ⇒ Object
merge(u2) replace self by u2 if u2 is aboslute soft_merge looks at each u2 components.
- #strip_user ⇒ Object
- #to_h ⇒ Object
- #to_json(_state = nil) ⇒ Object
-
#to_public ⇒ Object
strip password.
Instance Method Details
#reverse_merge(u2) ⇒ Object
uri=u2.merge(uri) does not work if uri is absolute
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/dr/base/uri.rb', line 119 def reverse_merge(u2) # return self unless uri.scheme u2 = u2.clone u2 = self.class.new(u2) unless u2.is_a?(self.class) if opaque.nil? == u2.opaque.nil? u2.soft_merge(self) else self end end |
#soft_merge(u2) ⇒ Object
merge(u2) replace self by u2 if u2 is aboslute soft_merge looks at each u2 components
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/dr/base/uri.rb', line 132 def soft_merge(u2) # we want automatic unescaping of u2 components u2 = self.class.new(u2) unless u2.is_a?(self.class) # only merge if we are both opaque or path like if opaque.nil? == u2.opaque.nil? components = uri.component if components.include?(:userinfo) components += %i[user password] components.delete(:userinfo) end components.each do |m| # path returns "" by default but we don't want to merge in this case if u2.respond_to?(m) && (v = u2.public_send(m)) && !((v == "") && (m == :path)) uri.public_send(:"#{m}=", v) end end end self end |
#strip_user ⇒ Object
112 113 114 115 116 |
# File 'lib/dr/base/uri.rb', line 112 def strip_user pub = dup pub.user = nil pub.to_s end |
#to_h ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dr/base/uri.rb', line 88 def to_h h = { uri: uri } components = uri.component components += %i[user password] if components.include?(:userinfo) components.each do |m| v = uri.public_send(m) v && h[m] = v end h end |
#to_json(_state = nil) ⇒ Object
99 100 101 102 103 |
# File 'lib/dr/base/uri.rb', line 99 def to_json(_state = nil) h=to_h h[:uri]=h[:uri].to_s #h[:uri] is a URIWrapper, so convert it to string so json does not convert it again h.to_json end |
#to_public ⇒ Object
strip password
106 107 108 109 110 |
# File 'lib/dr/base/uri.rb', line 106 def to_public pub = dup pub.password = nil pub.to_s end |