Class: URI::Source
- Inherits:
-
File
- Object
- File
- URI::Source
- 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
-
#gem_version ⇒ Object
readonly
Returns the value of attribute gem_version.
Class Method Summary collapse
Instance Method Summary collapse
- #check_host(v) ⇒ Object
- #gem_name ⇒ Object
- #line_number ⇒ Object
-
#set_path(v) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #to_s ⇒ Object
Instance Attribute Details
#gem_version ⇒ Object (readonly)
Returns the value of attribute gem_version.
29 30 31 |
# File 'lib/tapioca/helpers/source_uri.rb', line 29 def gem_version @gem_version end |
Class Method Details
.build(gem_name:, gem_version:, path:, line_number:) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tapioca/helpers/source_uri.rb', line 42 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
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tapioca/helpers/source_uri.rb', line 72 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 |
#gem_name ⇒ Object
55 56 57 |
# File 'lib/tapioca/helpers/source_uri.rb', line 55 def gem_name host end |
#line_number ⇒ Object
60 61 62 |
# File 'lib/tapioca/helpers/source_uri.rb', line 60 def line_number fragment end |
#set_path(v) ⇒ Object
rubocop:disable Naming/AccessorMethodName
65 66 67 68 69 |
# File 'lib/tapioca/helpers/source_uri.rb', line 65 def set_path(v) # rubocop:disable Naming/AccessorMethodName return if v.nil? @gem_version, @path = v.split("/", 2) end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/tapioca/helpers/source_uri.rb', line 84 def to_s "source://#{gem_name}/#{gem_version}#{path}##{line_number}" end |