diff --git a/core/rubygems/package.rbs b/core/rubygems/package.rbs new file mode 100644 index 0000000000..61baa6c81f --- /dev/null +++ b/core/rubygems/package.rbs @@ -0,0 +1,82 @@ +%a{annotate:rdoc:skip} +module Gem + # + # Example using a Gem::Package + # + # Builds a .gem file given a Gem::Specification. A .gem file is a tarball which + # contains a data.tar.gz, metadata.gz, checksums.yaml.gz and possibly + # signatures. + # + # require 'rubygems' + # require 'rubygems/package' + # + # spec = Gem::Specification.new do |s| + # s.summary = "Ruby based make-like utility." + # s.name = 'rake' + # s.version = PKG_VERSION + # s.requirements << 'none' + # s.files = PKG_FILES + # s.description = <<-EOF + # Rake is a Make-like program implemented in Ruby. Tasks + # and dependencies are specified in standard Ruby syntax. + # EOF + # end + # + # Gem::Package.build spec + # + # Reads a .gem file. + # + # require 'rubygems' + # require 'rubygems/package' + # + # the_gem = Gem::Package.new(path_to_dot_gem) + # the_gem.contents # get the files in the gem + # the_gem.extract_files destination_directory # extract the gem into a directory + # the_gem.spec # get the spec out of the gem + # the_gem.verify # check the gem is OK (contains valid gem specification, contains a not corrupt contents archive) + # + # #files are the files in the .gem tar file, not the Ruby files in the gem + # #extract_files and #contents automatically call #verify + # + class Package + # + # A header for a tar file + # + class TarHeader + # + # Creates a new TarHeader using `vals` + # + def initialize: (Hash[Symbol, untyped] vals) -> void + end + + # + # TarReader reads tar files and allows iteration over their items + # + class TarReader + # + # Creates a new TarReader on `io` and yields it to the block, if given. + # + def self.new: (untyped io) -> instance + | (untyped io) { (instance reader) -> void } -> nil + + # + # Class for reading entries out of a tar file + # + class Entry + # + # Creates a new tar entry for `header` that will be read from `io` + # + def initialize: (TarHeader header, untyped io) -> void + end + end + end +end diff --git a/test/stdlib/rubygems/GemPackage_test.rb b/test/stdlib/rubygems/GemPackage_test.rb new file mode 100644 index 0000000000..312823cb3a --- /dev/null +++ b/test/stdlib/rubygems/GemPackage_test.rb @@ -0,0 +1,39 @@ +require_relative "../test_helper" +require "rubygems/package" +require "stringio" + +class GemPackageTarHeaderSingletonTest < Test::Unit::TestCase + include TestHelper + + testing "singleton(::Gem::Package::TarHeader)" + + def test_new + assert_send_type "(Hash[Symbol, untyped]) -> Gem::Package::TarHeader", + Gem::Package::TarHeader, :new, { name: "foo.txt", size: 11, prefix: "", mode: 0644 } + end +end + +class GemPackageTarReaderSingletonTest < Test::Unit::TestCase + include TestHelper + + testing "singleton(::Gem::Package::TarReader)" + + def test_new + assert_send_type "(untyped) -> Gem::Package::TarReader", + Gem::Package::TarReader, :new, StringIO.new("".b) + assert_send_type "(untyped) { (Gem::Package::TarReader) -> void } -> nil", + Gem::Package::TarReader, :new, StringIO.new("".b) do end + end +end + +class GemPackageTarReaderEntrySingletonTest < Test::Unit::TestCase + include TestHelper + + testing "singleton(::Gem::Package::TarReader::Entry)" + + def test_new + header = Gem::Package::TarHeader.new(name: "foo.txt", size: 11, prefix: "", mode: 0644) + assert_send_type "(Gem::Package::TarHeader, untyped) -> Gem::Package::TarReader::Entry", + Gem::Package::TarReader::Entry, :new, header, StringIO.new("".b) + end +end