Sha256: 9cece3874f9f09ad21cd312cfbe86bea25dcb83e1dfbb0c39f1e64cae231fe23

Contents?: true

Size: 1.65 KB

Versions: 32

Compression:

Stored size: 1.65 KB

Contents

# typed: true
# frozen_string_literal: true

require "uri/file"

module URI
  class Source < URI::File
    extend T::Sig

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

    alias_method(:gem_name, :host)
    alias_method(:line_number, :fragment)

    sig { returns(T.nilable(String)) }
    attr_reader :gem_version

    class << self
      extend T::Sig

      sig do
        params(
          gem_name: String,
          gem_version: T.nilable(String),
          path: String,
          line_number: T.nilable(String),
        ).returns(URI::Source)
      end
      def build(gem_name:, gem_version:, path:, line_number:)
        super(
          {
            scheme: "source",
            host: gem_name,
            path: DEFAULT_PARSER.escape("/#{gem_version}/#{path}"),
            fragment: line_number,
          }
        )
      end
    end

    sig { params(v: T.nilable(String)).void }
    def set_path(v) # rubocop:disable Naming/AccessorMethodName
      return if v.nil?

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

    sig { params(v: T.nilable(String)).returns(T::Boolean) }
    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

    sig { returns(String) }
    def to_s
      "source://#{gem_name}/#{gem_version}#{path}##{line_number}"
    end

    if URI.respond_to?(:register_scheme)
      URI.register_scheme("SOURCE", self)
    else
      @@schemes["SOURCE"] = self
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
tapioca-0.11.9 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.8 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.7 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.6 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.5 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.4 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.3 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.2 lib/tapioca/helpers/source_uri.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/tapioca-0.11.1/lib/tapioca/helpers/source_uri.rb
tapioca-0.11.1 lib/tapioca/helpers/source_uri.rb
tapioca-0.11.0 lib/tapioca/helpers/source_uri.rb
tapioca-0.10.5 lib/tapioca/helpers/source_uri.rb