Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
foo ^^^
Represents writing to a local variable in a context that doesn’t have an explicit value.
foo, bar = baz ^^^ ^^^
Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
-> { _1 + _2 } ^^^^^^^^^^^^^^
The command manager registers and installs all the individual sub-commands supported by the gem command.
Extra commands can be provided by writing a rubygems_plugin.rb file in an installed gem. You should register your command against the Gem::CommandManager
instance, like this:
# file rubygems_plugin.rb require 'rubygems/command_manager' Gem::CommandManager.instance.register_command :edit
You should put the implementation of your command in rubygems/commands.
# file rubygems/commands/edit_command.rb class Gem::Commands::EditCommand < Gem::Command # ... end
See Gem::Command
for instructions on writing gem commands.
Raised when RubyGems is unable to load or activate a gem. Contains the name and version requirements of the gem that either conflicts with already activated gems or that RubyGems is otherwise unable to activate.
Raised when trying to activate a gem, and the gem exists on the system, but not the requested version. Instead of rescuing from this class, make sure to rescue from the superclass Gem::LoadError
to catch all types of load errors.
Signals that a file permission error is preventing the user from operating on the given directory.
Raised by Gem::Validator
when something is not right in a gem.
Raised by Gem::WebauthnListener when an error occurs during security device verification.
Run an instance of the gem program.
Gem::GemRunner
is only intended for internal use by RubyGems itself. It does not form any public API and may change at any time for any reason.
If you would like to duplicate functionality of ‘gem` commands, use the classes they call directly.
Capture
parse errors from Ripper
Prism
returns the errors with their messages, but Ripper
does not. To get them we must make a custom subclass.
Example:
puts RipperErrors.new(" def foo").call.errors # => ["syntax error, unexpected end-of-input, expecting ';' or '\\n'"]
Raised when an attempt is made to send a message to a closed port, or to retrieve a message from a closed and empty port. Ports may be closed explicitly with Ractor#close_outgoing
/close_incoming and are closed implicitly when a Ractor
terminates.
r = Ractor.new { sleep(500) } r.close_outgoing r.take # Ractor::ClosedError
ClosedError
is a descendant of StopIteration
, so the closing of the ractor will break the loops without propagating the error:
r = Ractor.new do loop do msg = receive # raises ClosedError and loop traps it puts "Received: #{msg}" end puts "loop exited" end 3.times{|i| r << i} r.close_incoming r.take puts "Continue successfully"
This will print:
Received: 0 Received: 1 Received: 2 loop exited Continue successfully
Encoding
conversion class.
Flags for integer nodes that correspond to the base of the integer.
Utility methods for using the RubyGems API.
The WebauthnListener
class retrieves an OTP after a user successfully WebAuthns with the Gem host. An instance opens a socket using the TCPServer
instance given and listens for a request from the Gem host. The request should be a GET request to the root path and contains the OTP code in the form of a query parameter ‘code`. The listener will return the code which will be used as the OTP for API requests.
Types of responses sent by the listener after receiving a request:
- 200 OK: OTP code was successfully retrieved - 204 No Content: If the request was an OPTIONS request - 400 Bad Request: If the request did not contain a query parameter `code` - 404 Not Found: The request was not to the root path - 405 Method Not Allowed: OTP code was not retrieved because the request was not a GET/OPTIONS request
Example usage:
thread = Gem::WebauthnListener.listener_thread("https://rubygems.example", server) thread.join otp = thread[:otp] error = thread[:error]
The WebauthnListener
Response class is used by the WebauthnListener
to create responses to be sent to the Gem host. It creates a Gem::Net::HTTPResponse instance when initialized and can be converted to the appropriate format to be sent by a socket using ‘to_s`. Gem::Net::HTTPResponse instances cannot be directly sent over a socket.
Types of response classes:
- OkResponse - NoContentResponse - BadRequestResponse - NotFoundResponse - MethodNotAllowedResponse
Example usage:
server = TCPServer.new(0) socket = server.accept response = OkResponse.for("https://rubygems.example") socket.print response.to_s socket.close
The WebauthnPoller
class retrieves an OTP after a user successfully WebAuthns. An instance polls the Gem host for the OTP code. The polling request (api/v1/webauthn_verification/<webauthn_token>/status.json) is sent to the Gem host every 5 seconds and will timeout after 5 minutes. If the status field in the json response is “success”, the code field will contain the OTP code.
Example usage:
thread = Gem::WebauthnPoller.poll_thread( {}, "RubyGems.org", "https://rubygems.org/api/v1/webauthn_verification/odow34b93t6aPCdY", { email: "email@example.com", password: "password" } ) thread.join otp = thread[:otp] error = thread[:error]
Mixin methods for commands that work with gemspecs.
Helper methods for both Gem::Installer
and Gem::Uninstaller
Mixin methods for Gem::Command
to promote available RubyGems update