Class: URI::Source
- Inherits:
-
File
- Object
- File
- URI::Source
- Defined in:
- lib/ruby_lsp/requests/support/source_uri.rb
Overview
Must be kept in sync with the one in Tapioca github.com/Shopify/tapioca/blob/main/lib/tapioca/helpers/source_uri.rb
Constant Summary collapse
- COMPONENT =
[ :scheme, :gem_name, :gem_version, :path, :line_number, ].freeze
- PARSER =
urifor 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, namelyextract/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
- @@schemes =
Fallback for URI <0.11.0
@@schemes
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.
-
#set_path(v) ⇒ Object
: (String? v) -> void.
-
#to_s ⇒ Object
: -> String.
Instance Attribute Details
#gem_version ⇒ Object (readonly)
: String?
29 30 31 |
# File 'lib/ruby_lsp/requests/support/source_uri.rb', line 29 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
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_lsp/requests/support/source_uri.rb', line 33 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
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_lsp/requests/support/source_uri.rb', line 56 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
: (String? v) -> void
46 47 48 49 50 51 52 53 |
# File 'lib/ruby_lsp/requests/support/source_uri.rb', line 46 def set_path(v) # rubocop:disable Naming/AccessorMethodName return if v.nil? gem_version, path = v.delete_prefix("/").split("/", 2) @gem_version = gem_version #: String? @path = path #: String? end |
#to_s ⇒ Object
: -> String
68 69 70 |
# File 'lib/ruby_lsp/requests/support/source_uri.rb', line 68 def to_s "source://#{gem_name}/#{gem_version}/#{path}##{line_number}" end |