Class: Tapioca::SourceURI
- Inherits:
-
URI::File
- Object
- URI::File
- Tapioca::SourceURI
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/helpers/source_uri.rb
Constant Summary collapse
- COMPONENT =
[ :scheme, :gem_name, :gem_version, :path, :line_number, ].freeze
- 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.
const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER
Instance Attribute Summary collapse
-
#gem_version ⇒ Object
readonly
: String?.
Class Method Summary collapse
-
.build(gem_name:, gem_version:, path:, line_number:) ⇒ Object
: (gem_name: String, gem_version: String?, path: String, line_number: String?) -> instance.
Instance Method Summary collapse
-
#check_host(v) ⇒ Object
: (String? v) -> bool.
-
#gem_name ⇒ Object
: -> String?.
-
#line_number ⇒ Object
: -> String?.
-
#set_path(v) ⇒ Object
: (String? v) -> void.
-
#to_s ⇒ Object
: -> String.
Instance Attribute Details
#gem_version ⇒ Object (readonly)
: String?
26 27 28 |
# File 'lib/tapioca/helpers/source_uri.rb', line 26 def gem_version @gem_version end |
Class Method Details
.build(gem_name:, gem_version:, path:, line_number:) ⇒ Object
: (gem_name: String, gem_version: String?, path: String, line_number: String?) -> instance
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tapioca/helpers/source_uri.rb', line 32 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
: (String? v) -> bool
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tapioca/helpers/source_uri.rb', line 62 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
: -> String?
45 46 47 |
# File 'lib/tapioca/helpers/source_uri.rb', line 45 def gem_name host end |
#line_number ⇒ Object
: -> String?
50 51 52 |
# File 'lib/tapioca/helpers/source_uri.rb', line 50 def line_number fragment end |
#set_path(v) ⇒ Object
: (String? v) -> void
55 56 57 58 59 |
# File 'lib/tapioca/helpers/source_uri.rb', line 55 def set_path(v) # rubocop:disable Naming/AccessorMethodName return if v.nil? @gem_version, @path = v.split("/", 2) end |
#to_s ⇒ Object
: -> String
74 75 76 |
# File 'lib/tapioca/helpers/source_uri.rb', line 74 def to_s "source://#{gem_name}/#{gem_version}#{path}##{line_number}" end |