PHP 8.2.31
Preview: stub_specification.rb Size: 4.96 KB
//proc/thread-self/root/opt/alt/ruby33/share/rubygems/rubygems/stub_specification.rb

# frozen_string_literal: true

##
# Gem::StubSpecification reads the stub: line from the gemspec.  This prevents
# us having to eval the entire gemspec in order to find out certain
# information.

class Gem::StubSpecification < Gem::BasicSpecification
  # :nodoc:
  PREFIX = "# stub: "

  # :nodoc:
  OPEN_MODE = "r:UTF-8:-"

  class StubLine # :nodoc: all
    attr_reader :name, :version, :platform, :require_paths, :extensions,
                :full_name

    NO_EXTENSIONS = [].freeze

    # These are common require paths.
    REQUIRE_PATHS = { # :nodoc:
      "lib" => "lib",
      "test" => "test",
      "ext" => "ext",
    }.freeze

    # These are common require path lists.  This hash is used to optimize
    # and consolidate require_path objects.  Most specs just specify "lib"
    # in their require paths, so lets take advantage of that by pre-allocating
    # a require path list for that case.
    REQUIRE_PATH_LIST = { # :nodoc:
      "lib" => ["lib"].freeze,
    }.freeze

    def initialize(data, extensions)
      parts          = data[PREFIX.length..-1].split(" ", 4)
      @name          = -parts[0]
      @version       = if Gem::Version.correct?(parts[1])
        Gem::Version.new(parts[1])
      else
        Gem::Version.new(0)
      end

      @platform      = Gem::Platform.new parts[2]
      @extensions    = extensions
      @full_name     = if platform == Gem::Platform::RUBY
        "#{name}-#{version}"
      else
        "#{name}-#{version}-#{platform}"
      end

      path_list = parts.last
      @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0").map! do |x|
        REQUIRE_PATHS[x] || x
      end
    end
  end

  def self.default_gemspec_stub(filename, base_dir, gems_dir)
    new filename, base_dir, gems_dir, true
  end

  def self.gemspec_stub(filename, base_dir, gems_dir)
    new filename, base_dir, gems_dir, false
  end

  attr_reader :base_dir, :gems_dir

  def initialize(filename, base_dir, gems_dir, default_gem)
    super()

    self.loaded_from = filename
    @data            = nil
    @name            = nil
    @spec            = nil
    @base_dir        = base_dir
    @gems_dir        = gems_dir
    @default_gem     = default_gem
  end

  ##
  # True when this gem has been activated

  def activated?
    @activated ||= !loaded_spec.nil?
  end

  def default_gem?
    @default_gem
  end

  def build_extensions # :nodoc:
    return if default_gem?
    return if extensions.empty?

    to_spec.build_extensions
  end

  ##
  # If the gemspec contains a stubline, returns a StubLine instance. Otherwise
  # returns the full Gem::Specification.

  def data
    unless @data
      begin
        saved_lineno = $.

        Gem.open_file loaded_from, OPEN_MODE do |file|
          file.readline # discard encoding line
          stubline = file.readline
          if stubline.start_with?(PREFIX)
            extline = file.readline

            extensions =
              if extline.delete_prefix!(PREFIX)
                extline.chomp!
                extline.split "\0"
              else
                StubLine::NO_EXTENSIONS
              end

            stubline.chomp! # readline(chomp: true) allocates 3x as much as .readline.chomp!
            @data = StubLine.new stubline, extensions
          end
        rescue EOFError
        end
      ensure
        $. = saved_lineno
      end
    end

    @data ||= to_spec
  end

  private :data

  def raw_require_paths # :nodoc:
    data.require_paths
  end

  def missing_extensions?
    return false if default_gem?
    return false if extensions.empty?
    return false if File.exist? gem_build_complete_path

    to_spec.missing_extensions?
  end

  ##
  # Name of the gem

  def name
    data.name
  end

  ##
  # Platform of the gem

  def platform
    data.platform
  end

  ##
  # Extensions for this gem

  def extensions
    data.extensions
  end

  ##
  # Version of the gem

  def version
    data.version
  end

  def full_name
    data.full_name
  end

  ##
  # The full Gem::Specification for this gem, loaded from evalling its gemspec

  def spec
    @spec ||= loaded_spec if @data
    @spec ||= Gem::Specification.load(loaded_from)
  end
  alias_method :to_spec, :spec

  ##
  # Is this StubSpecification valid? i.e. have we found a stub line, OR does
  # the filename contain a valid gemspec?

  def valid?
    data
  end

  ##
  # Is there a stub line present for this StubSpecification?

  def stubbed?
    data.is_a? StubLine
  end

  def ==(other) # :nodoc:
    self.class === other &&
      name == other.name &&
      version == other.version &&
      platform == other.platform
  end

  alias_method :eql?, :== # :nodoc:

  def hash # :nodoc:
    name.hash ^ version.hash ^ platform.hash
  end

  def <=>(other) # :nodoc:
    sort_obj <=> other.sort_obj
  end

  def sort_obj # :nodoc:
    [name, version, Gem::Platform.sort_priority(platform)]
  end

  private

  def loaded_spec
    spec = Gem.loaded_specs[name]
    return unless spec && spec.version == version && spec.default_gem? == default_gem?

    spec
  end
end

Directory Contents

Dirs: 15 × Files: 71

Name Size Perms Modified Actions
commands DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
core_ext DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
defaults DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
ext DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
package DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
request DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
resolver DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
security DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
source DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
ssl_certs DIR
- drwxr-xr-x 2026-04-07 13:52:12
Edit Download
util DIR
- drwxr-xr-x 2026-04-30 07:09:22
Edit Download
vendor DIR
- drwxr-xr-x 2026-04-07 13:52:11
Edit Download
3.00 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
8.17 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.96 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
3.71 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
15.97 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.64 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1022 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
15.79 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
7.35 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
8.45 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
9.91 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.55 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.04 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
3.13 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
4.53 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
7.33 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
498 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
11.17 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
394 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.89 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
27.68 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
771 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
349 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
323 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
6.39 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
3.61 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.38 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
125 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
18.83 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
3.79 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.77 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
8.35 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
795 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
8.50 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
232 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
9.38 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
8.70 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
11.29 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
7.00 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
9.44 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.96 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.92 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.04 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
21.69 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.06 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
66 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.78 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.42 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
69.10 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
15.59 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
5.21 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
6.16 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
4.96 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.06 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
10.94 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
411 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
1.85 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.38 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
784 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
13.10 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.46 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
3.63 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
81 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
233 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
79 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
111 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
228 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
73 B lrw-r--r-- 2026-04-07 13:52:24
Edit Download
12.98 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.17 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download
2.42 KB lrw-r--r-- 2026-04-07 13:52:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).