module TripletInterruptus

A SCP Triplet is not a canonical URI. It doesn’t follow any RFCs that I’ve been able to find, and it’s difficult to reason about if you try to force it into a URI::Generic as-is. TripletInterruptus provides helper methods that preserve the upstream behavior of URI::Generic but extend it just enough that it doesn’t choke on SCP Triplets if they’re passed.

Constants

SCHEME

Determine if a string is prefixed with a URI scheme like http:// or ssh://

TRIPLET

Determine if a string can be teased apart into URI-like components

Public Instance Methods

parse(uri) click to toggle source
Calls superclass method
# File lib/uri/triplets.rb, line 68
def parse(uri)
  return build_triplet(uri) if triplet?(uri)

  super(uri)
end
split(uri) click to toggle source
Calls superclass method
# File lib/uri/triplets.rb, line 74
def split(uri)
  return super(uri) unless triplet?(uri)

  parts = parse_triplet(uri)
  [nil, parts[:userinfo], parts[:host], nil,
   nil, parts[:path], nil, nil, nil]
end
triplet?(address) click to toggle source
# File lib/uri/triplets.rb, line 82
def triplet?(address)
  address.match(TRIPLET) && !address.match(SCHEME)
end

Private Instance Methods

build_triplet(address) click to toggle source
# File lib/uri/triplets.rb, line 86
def build_triplet(address)
  values = parse_triplet(address)
  return nil unless values

  URI.scheme_list[URI.default_triplet_type].build(values)
end
parse_triplet(address) click to toggle source
# File lib/uri/triplets.rb, line 94
def parse_triplet(address)
  parts = address.match(TRIPLET)
  return nil unless parts

  parts.names.map(&:to_sym).zip(parts.captures).to_h
end