Class: URI::Source

Inherits:
File
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/helpers/source_uri.rb

Constant Summary collapse

COMPONENT =
T.let(
  [
    :scheme,
    :gem_name,
    :gem_version,
    :path,
    :line_number,
  ].freeze,
  T::Array[Symbol],
)
PARSER =

‘uri` for Ruby 3.4 switched the default parser from RFC2396 to RFC3986. The new parser emits a deprecation warning on a few methods and delegates them to RFC2396, namely `extract`/`make_regexp`/`escape`/`unescape`. On earlier versions of the uri gem, the RFC2396_PARSER constant doesn’t exist, so it needs some special handling to select a parser that doesn’t emit deprecations. While it was backported to Ruby 3.1, users may have the uri gem in their own bundle and thus not use a compatible version.

T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gem_versionObject (readonly)

Returns the value of attribute gem_version.



32
33
34
# File 'lib/tapioca/helpers/source_uri.rb', line 32

def gem_version
  @gem_version
end

Class Method Details

.build(gem_name:, gem_version:, path:, line_number:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/tapioca/helpers/source_uri.rb', line 45

def build(gem_name:, gem_version:, path:, line_number:)
  super(
    {
      scheme: "source",
      host: gem_name,
      path: PARSER.escape("/#{gem_version}/#{path}"),
      fragment: line_number,
    }
  )
end

Instance Method Details

#check_host(v) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/tapioca/helpers/source_uri.rb', line 65

def check_host(v)
  return true unless v

  if /[A-Za-z][A-Za-z0-9\-_]*/ !~ v
    raise InvalidComponentError,
      "bad component(expected gem name): #{v}"
  end

  true
end

#set_path(v) ⇒ Object

rubocop:disable Naming/AccessorMethodName



58
59
60
61
62
# File 'lib/tapioca/helpers/source_uri.rb', line 58

def set_path(v) # rubocop:disable Naming/AccessorMethodName
  return if v.nil?

  @gem_version, @path = v.split("/", 2)
end

#to_sObject



77
78
79
# File 'lib/tapioca/helpers/source_uri.rb', line 77

def to_s
  "source://#{gem_name}/#{gem_version}#{path}##{line_number}"
end