### Manually install RubyGems Source: https://github.com/ruby/rubygems/blob/master/README.md Instructions for manually installing RubyGems by downloading, unpacking, and running the setup script. Use `ruby setup.rb --help` for more options. ```bash $ ruby setup.rb ``` -------------------------------- ### Install Rubygems from Source Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Instructions for installing Rubygems by downloading and compiling from source. ```bash ruby setup.rb ``` -------------------------------- ### Install a Gem using gem install Source: https://github.com/ruby/rubygems/blob/master/README.md Use the `gem install` command to download and install a Gem from RubyGems.org into your Ruby environment. This example shows how to install the Faraday Gem. ```bash gem install faraday ``` -------------------------------- ### Install Bundler to User Directory Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Install Bundler without elevated privileges by directing the installation to your home directory. Remember to add the user gem bin directory to your PATH. ```bash gem install bundler --user-install ``` -------------------------------- ### Install or Update Bundler Source: https://github.com/ruby/rubygems/blob/master/bundler/README.md Installs or updates Bundler to the latest stable version. Use the --pre flag to install a prerelease version if available. ```bash gem install bundler ``` -------------------------------- ### Install Pre-release Bundler Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Installs a pre-release version of Bundler and updates to a specific pre-release version. ```bash gem install bundler --pre bundle update --bundler=4.0.0.beta1 ``` -------------------------------- ### Install and Update Bundler Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Installs the latest Bundler and then updates it to the latest version. ```bash gem install bundler bundle update --bundler ``` -------------------------------- ### Run Local Bundler Commands Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute Bundler commands, such as 'bundle install', directly from your local clone of the Bundler repository. ```ruby bin/bundle install ``` -------------------------------- ### Install Bundler with Elevated Privileges Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Use this command when you encounter permission errors during gem installation and have the necessary privileges to install globally. ```bash sudo gem install bundler ``` -------------------------------- ### Local Setup for Bundler Testing Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Create a temporary directory and initialize a new Bundler project for local testing. This isolates your test environment. ```bash cd tmp mkdir [name of directory for local testing] && cd [name of directory for local testing] dbundle init ``` -------------------------------- ### Install Local RubyGems Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Use this command to install gems from your local RubyGems clone. This is useful for testing changes to the gem installation process. ```ruby ruby -Ilib exe/gem install ``` -------------------------------- ### Load and use a Gem in a Ruby program Source: https://github.com/ruby/rubygems/blob/master/README.md After installing a Gem, you can load it into your Ruby program using `require` and then use its functionality. This example demonstrates loading the Faraday gem and making an HTTP GET request. ```ruby require 'faraday' response = Faraday.get('https://rubygems.org') # do something with `response`... ``` -------------------------------- ### Setup RubyGems Development Dependencies Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Run this rake task to install development dependencies for RubyGems. Consider using a Ruby version manager if you encounter permission errors. ```ruby bin/rake setup ``` -------------------------------- ### Registering Plugins for On-Demand Loading Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc This approach suggests registering plugins with specific types (e.g., :install, :command) to allow RubyGems to load them on demand when commands are invoked, rather than at startup. This aims to reduce the initial load time and memory usage of RubyGems. ```ruby Gem.register_plugin(:install, 'some_plugin/gem/installer') Gem.register_plugin(:command, 'some_plugin/gem/command') ``` -------------------------------- ### Installing Net::HTTP::Persistent Source: https://github.com/ruby/rubygems/blob/master/bundler/lib/bundler/vendor/net-http-persistent/README.rdoc The command to install the net-http-persistent gem using RubyGems. ```bash gem install net-http-persistent ``` -------------------------------- ### Registering Command Plugins Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc Example of registering command plugins, including a specific plugin for rubygems-testing that might load libraries and register hooks. ```ruby register_plugin(:command, 'gemcutter/push_command') register_plugin(:command, 'rubygems-testing/install_hooks') ``` -------------------------------- ### Check Bundler Version Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Verify the currently installed version of Bundler. ```bash bundle -v ``` -------------------------------- ### Install and Downgrade Bundler to a Specific Version Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Installs a specific version of Bundler and then updates it to that version. ```bash gem install bundler -v 2.7.2 bundle update --bundler=2.7.2 ``` -------------------------------- ### Install Pre-release Rubygems Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Use this flag to update Rubygems to the latest pre-release version. ```bash gem update --system --pre ``` -------------------------------- ### Run Specific Unit and Integration Tests Source: https://github.com/ruby/rubygems/blob/master/doc/PULL_REQUESTS.md If the full test suite cannot be run, execute unit tests and relevant integration specs for the modified Bundler command or domain. This example shows running tests related to 'bundle update'. ```shell $ bin/rspec spec/bundler $ bin/rspec spec/commands/update_spec.rb ``` -------------------------------- ### Manage Application Dependencies with Bundler Source: https://github.com/ruby/rubygems/blob/master/bundler/README.md A sequence of commands to initialize Bundler for an application, add a specific gem (rspec), install all dependencies, and execute a command (rspec) using the bundled gems. ```bash bundle init bundle add rspec bundle install bundle exec rspec ``` -------------------------------- ### Uninstall Problematic Gems Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Remove 'rubygems-bundler' and 'open_gem' if they are installed and causing conflicts. This example shows usage with RVM. ```bash rvm gemset use global # if using rvm gem uninstall rubygems-bundler open_gem ``` -------------------------------- ### Basic Usage of Net::HTTP::Persistent Source: https://github.com/ruby/rubygems/blob/master/bundler/lib/bundler/vendor/net-http-persistent/README.rdoc Demonstrates making two requests to the same server using persistent connections. The connection is kept alive between requests. Includes performing a GET and a POST request. Remember to shut down the HTTP object when done. ```ruby require 'net/http/persistent' uri = URI 'http://example.com/awesome/web/service' http = Net::HTTP::Persistent.new name: 'my_app_name' # perform a GET response = http.request uri # create a POST post_uri = uri + 'create' post = Net::HTTP::Post.new post_uri.path post.set_form_data 'some' => 'cool data' # perform the POST, the URI is always required response = http.request post_uri, post # if you are done making http requests, or won't make requests for several # minutes http.shutdown ``` -------------------------------- ### Install Git Hooks for Code Style Checks Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Optionally configure git hooks to automatically check code style compliance before each commit. ```ruby bin/rake git_hooks ``` -------------------------------- ### Check for Problematic Gems Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md List installed versions of 'rubygems-bundler' and 'open_gem', which are known to cause issues. ```bash gem list rubygems-bundler open_gem ``` -------------------------------- ### Re-install Gems with Bundler Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Attempt to install gems again after cleaning up potential conflicts or outdated configurations. ```bash bundle install ``` -------------------------------- ### RubyGems Test Case Gemfile Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Example Gemfile for testing with RubyGems. It specifies a source and includes a gem. Place breakpoints using `binding.break` or `binding.pry`. ```ruby # frozen_string_literal: true source "https://rubygems.org" gem 'tiny_css' ``` -------------------------------- ### Check RubyGems version Source: https://github.com/ruby/rubygems/blob/master/README.md Check the installed version of RubyGems by running `gem --version` in your terminal. ```bash gem --version ``` -------------------------------- ### PowerShell Function for Local Bundler on Windows Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Define a PowerShell function to execute Bundler from your local clone on Windows. This example also sets the RUBYOPT environment variable for debugging. ```powershell $Env:RUBYOPT="-rdebug" function dbundle { & "ruby.exe" E:\\\\[repo root]\\bin\\bundle $args } ``` -------------------------------- ### Markdown Frontmatter for RubyGems Guides Source: https://github.com/ruby/rubygems/blob/master/doc/DOCUMENTATION.md When contributing to RubyGems Guides, include this frontmatter in your Markdown files. It specifies layout, title, and navigation URLs. ```markdown --- layout: default title: Your Guide Title Here url: /your_guide_url previous: /previous_guide next: /next_guide --- ``` -------------------------------- ### Test::Unit Template for Newgem Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt This is a Test::Unit template for generating new gems. It provides a basic test case setup. ```ruby require "test/unit" class NewgemTest < Test::Unit::TestCase def test_that_it_works assert_equal 42, Newgem.new.the_answer end end ``` -------------------------------- ### Configure Gemfile with Local Gem Source Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Specify a local file path as a gem source in your Gemfile to use gems built during a test run. This is useful for testing specific gem versions or failing examples. ```ruby # frozen_string_literal: true source "file:///[path to repo root]/tmp/1/gems/remote1/" gem "rack", '=0.9.1' ``` -------------------------------- ### Registering Post-Install Hooks Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc Demonstrates how a plugin might register a post-install hook for the InstallCommand. Hooks are expected to be callable objects (like lambdas) that respond to #call. ```ruby Gem::Commands::InstallCommand.hooks[:post_install] << RubyGemsTesting.post_install_hook ``` -------------------------------- ### PubGrub Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A dependency resolution library implementing the PubGrub algorithm. ```ruby module PubGrub # Your code goes here... end ``` -------------------------------- ### Setting up Interactive Debugging with `debug` or `pry-byebug` Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Launch Bundler with an interactive debugger by setting the `RUBYOPT` environment variable. This allows for line-by-line code execution and inspection. ```bash RUBYOPT=-rdebug dbundle # for the debug gem ``` ```bash RUBYOPT=-rpry-byebug dbundle # for pry-byebug ``` -------------------------------- ### PubGrub Basic Package Source Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A basic implementation of a package source for PubGrub. ```ruby module PubGrub class BasicPackageSource def initialize(packages) @packages = packages end def packages @packages.keys end def versions_for(package) @packages[package].keys end def dependencies_for(package, version) @packages[package][version] end end end ``` -------------------------------- ### Dry Run Release Preparation Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Verify the release preparation steps without making actual changes. This is useful for checking the process before a real release. ```bash DRYRUN=1 bin/rake prepare_release[] ``` -------------------------------- ### Listing Available Bundler Commands Source: https://github.com/ruby/rubygems/blob/master/doc/DOCUMENTATION.md To see a list of all commands available in the Bundler CLI, use the `bundle help` command in your terminal. ```bash $ bundle help ``` -------------------------------- ### Previewing Bundler Man Page Changes Source: https://github.com/ruby/rubygems/blob/master/doc/DOCUMENTATION.md After making changes to a `.ronn` file, run these commands to build and preview the man page. You need to re-run `bin/rake man:build` if you make further edits. ```bash $ bin/rake dev:deps $ bin/rake man:build $ man ./bundler/lib/bundler/man/bundle-cookies.1 ``` -------------------------------- ### Run All Bundler Specs Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute all Bundler specifications, including both regular and realworld specs. This command can take a significant amount of time. ```ruby bin/rake spec:all ``` -------------------------------- ### PubGrub Partial Solution Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a partial solution during PubGrub dependency resolution. ```ruby module PubGrub class PartialSolution attr_reader :assignments def initialize(assignments = []) @assignments = assignments.sort_by(&:to_s) end def add(assignment) new_assignments = (@assignments + [assignment]).uniq.sort_by(&:to_s) PartialSolution.new(new_assignments) end def ==(other) other.is_a?(PartialSolution) && @assignments == other.assignments end def hash @assignments.hash end def to_s @assignments.join(", ") end end end ``` -------------------------------- ### Prepare Release for Specific Version Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Prepares for a minor or major release by creating a release branch, updating versions, and generating changelogs for a specified version. ```bash rake prepare_release[4.0.0.beta3] ``` -------------------------------- ### PubGrub Version Solver Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt The main class for solving version constraints using the PubGrub algorithm. ```ruby module PubGrub class VersionSolver def initialize(source) @source = source @assignments = [] @incompatibilities = [] end def solve(constraints) constraints.each { |constraint| add_constraint(constraint) } resolve end def add_constraint(constraint) @assignments << constraint end def resolve # Simplified resolution logic for demonstration # In a real implementation, this would involve complex backtracking and constraint propagation solution = PartialSolution.new(@assignments) # Check for obvious incompatibilities (e.g., conflicting version constraints) # For this example, we'll assume a valid solution can be formed if no direct conflicts are added solution end def add_incompatibility(incompatibility) @incompatibilities << incompatibility end end end ``` -------------------------------- ### Running Bundler Documentation Tests Source: https://github.com/ruby/rubygems/blob/master/doc/DOCUMENTATION.md Before submitting a pull request, run these RSpec tests to ensure the quality and correctness of the documentation. The `help_spec.rb` and `quality_spec.rb` files are particularly important. ```bash $ bin/rspec spec/commands/help_spec.rb $ bin/rspec spec/quality_spec.rb ``` -------------------------------- ### PubGrub Strategy Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Defines strategies for PubGrub dependency resolution. ```ruby module PubGrub class Strategy # Your code goes here... end end ``` -------------------------------- ### Simple Plugin Registration Module Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc A basic module for registering plugins by type and path. Gem::CommandManager would use this hash to determine which files to load. ```ruby module Gem @plugins = Hash.new { |h,k| h[k] = [] } def self.register_plugin type, path @plugins[type] << path end end ``` -------------------------------- ### Creating a New Bundler Man Page File Source: https://github.com/ruby/rubygems/blob/master/doc/DOCUMENTATION.md To create a new man page for a Bundler command, create a `.ronn` file in the specified directory. The filename should follow the pattern `bundle-.1.ronn`. ```bash bundler/lib/bundler/man/bundle-cookies.1.ronn ``` -------------------------------- ### PubGrub Version Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a version for a package in PubGrub. ```ruby module PubGrub class Version attr_reader :version def initialize(version) @version = version end def ==(other) other.is_a?(Version) && @version == other.version end def hash @version.hash end def to_s @version end end end ``` -------------------------------- ### Release Bundler Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Executes the full release process for Bundler, including packaging, tagging, and uploading artifacts. ```bash bin/rake bundler:release ``` -------------------------------- ### Run RuboCop for Code Formatting Source: https://github.com/ruby/rubygems/blob/master/doc/PULL_REQUESTS.md Execute RuboCop to ensure code formatting and style adhere to project guidelines. Failures in this check will cause GitHub Actions builds to fail. ```shell $ bin/rake rubocop ``` -------------------------------- ### Check Ruby Version Source: https://github.com/ruby/rubygems/blob/master/doc/TROUBLESHOOTING.md Display the version of Ruby being used. ```bash ruby -v ``` -------------------------------- ### PubGrub Package Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a package in the PubGrub dependency resolution system. ```ruby module PubGrub class Package attr_reader :name def initialize(name) @name = name end def ==(other) other.is_a?(Package) && @name == other.name end def hash @name.hash end def to_s @name end end end ``` -------------------------------- ### Run Individual Bundler Spec File Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute a single spec file for Bundler. This is useful for targeted testing during development. ```ruby bin/rspec spec/install/gems/standalone_spec.rb ``` -------------------------------- ### Run Bundler Realworld Specs Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute the higher-level 'realworld' specifications for Bundler. These are also run in the continuous integration pipeline. ```ruby bin/rake spec:realworld ``` -------------------------------- ### Thor Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A toolkit for building CLIs (Command Line Interfaces) in Ruby. ```ruby module Thor # Your code goes here... end ``` -------------------------------- ### Hook Execution Policy Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc Illustrates the policy for executing hook lambdas: if a hook fails, it should be caught and warned about, but the main operation (like install/uninstall) must continue. ```ruby RubyGemsTesting.post_install_hook # => lambda { |command_instance| ... use command instance to work out what to do and do it ... } ``` -------------------------------- ### Thor Actions: Directory Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Action for creating a directory. ```ruby module Thor module Actions class Directory < Base def initialize(source, destination, config = {}) # rubocop:disable Metrics/ParameterLists super(config) @source = source @destination = destination @config = config end def invoke! directory(@source, @destination, @config) end def undo! remove_dir(@destination, @config) end end end end ``` -------------------------------- ### PubGrub Static Package Source Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A package source for PubGrub that uses static data. ```ruby module PubGrub class StaticPackageSource def initialize(packages) @packages = packages end def packages @packages.keys end def versions_for(package) @packages[package].keys end def dependencies_for(package, version) @packages[package][version] end end end ``` -------------------------------- ### PubGrub Version Range Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a range of versions for a package in PubGrub. ```ruby module PubGrub class VersionRange attr_reader :min, :max def initialize(min, max) @min = min @max = max end def include?(version) (@min.nil? || version >= @min) && (@max.nil? || version <= @max) end def ==(other) other.is_a?(VersionRange) && @min == other.min && @max == other.max end def hash [@min, @max].hash end def to_s "#{@min}..#{@max}" end end end ``` -------------------------------- ### Alternative Plugin Registration for Commands Source: https://github.com/ruby/rubygems/wiki/Plugin-Discussion.rdoc An alternative suggestion for registering commands, proposing a more specific API like Gem.register_command for command-related plugins. This distinguishes command registration from general plugin registration. ```ruby Gem.register_command(:push, 'path/to/gemcutter/plugin') ``` -------------------------------- ### Thor Actions: Create File Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Action for creating a new file with specified content. ```ruby module Thor module Actions class CreateFile < Base def initialize(file, content, config = {}) # rubocop:disable Metrics/ParameterLists super(config) @file = file @content = content @config = config end def invoke! create_file(@file, @content, @config) end def undo! remove_file(@file, @config) end end end end ``` -------------------------------- ### Debugging with Pry Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Launch Bundler with Pry requiring it via `RUBYOPT`. This ensures Pry is available even if not explicitly in the Gemfile, allowing `binding.pry` to function. ```bash RUBYOPT=-rpry dbundle ``` -------------------------------- ### PubGrub Failure Writer Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Handles writing failure information during PubGrub resolution. ```ruby module PubGrub class FailureWriter def initialize(io) @io = io end def write(failure) @io.puts "Unable to satisfy the following constraints:" failure.each do |incompatibility| @io.puts "- #{incompatibility.to_s}" end end end end ``` -------------------------------- ### Prepare Release Task Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Use this rake task to prepare a new release by checking out the appropriate stable branch, cherry-picking merged PRs, and updating version files and changelogs. ```ruby bin/rake prepare_release[] ``` -------------------------------- ### Running Bundler with Debugger for Test Case Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Execute Bundler with the `debug` gem required via `RUBYOPT` to hit breakpoints defined in your code. ```bash RUBYOPT=-rdebug dbundle ``` -------------------------------- ### Run RubyGems Test Suite Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute the complete test suite for RubyGems using the test-unit framework. ```ruby bin/rake test ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/ruby/rubygems/blob/master/doc/PULL_REQUESTS.md Execute the complete test suite using parallel_rspec before submitting a pull request. ```shell $ bin/parallel_rspec ``` -------------------------------- ### Net::HTTP::Persistent Timed Stack Multi Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A multi-threaded timed stack implementation for persistent HTTP connections. ```ruby module Net module HTTP class Persistent class TimedStackMulti # Your code goes here... end end end end ``` -------------------------------- ### PubGrub RubyGems Integration Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Integration layer for PubGrub to work with RubyGems. ```ruby module PubGrub class RubyGems def initialize(source) @source = source end def packages @source.packages.map { |p| Package.new(p) } end def versions_for(package) @source.versions_for(package.name).map { |v| Version.new(v) } end def dependencies_for(package, version) @source.dependencies_for(package.name, version.to_s).map do |dep_name, dep_constraint| [Package.new(dep_name), VersionConstraint.new(dep_constraint)] end end end end ``` -------------------------------- ### PubGrub Version Union Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a union of version ranges in PubGrub. ```ruby module PubGrub class VersionUnion attr_reader :ranges def initialize(ranges = []) @ranges = ranges.sort_by { |r| [r.min.to_s, r.max.to_s] } end def include?(version) @ranges.any? { |range| range.include?(version) } end def ==(other) other.is_a?(VersionUnion) && @ranges == other.ranges end def hash @ranges.hash end def to_s @ranges.join(" or ") end end end ``` -------------------------------- ### PubGrub Assignment Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents an assignment of a version to a package in PubGrub. ```ruby module PubGrub class Assignment attr_reader :package, :version def initialize(package, version) @package = package @version = version end def ==(other) other.is_a?(Assignment) && @package == other.package && @version == other.version end def hash [@package, @version].hash end def to_s "#{@package}=#{@version}" end end end ``` -------------------------------- ### Test Helper for Test::Unit Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A helper file for Test::Unit tests, typically used to set up the testing environment. ```ruby require "test/unit" ``` -------------------------------- ### PubGrub Version Constraint Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a version constraint for a package in PubGrub. ```ruby module PubGrub class VersionConstraint attr_reader :constraint def initialize(constraint) @constraint = constraint end def ==(other) other.is_a?(VersionConstraint) && @constraint == other.constraint end def hash @constraint.hash end def to_s @constraint end end end ``` -------------------------------- ### Thor Actions: Empty Directory Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Action for creating an empty directory. ```ruby module Thor module Actions class EmptyDirectory < Base def initialize(destination, config = { verbose: true }) super(config) @destination = destination end def invoke! empty_directory(@destination, @config) end def undo! remove_dir(@destination, @config) end end end end ``` -------------------------------- ### Thor Shell Basic Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A basic shell implementation for Thor, handling input and output. ```ruby module Thor module Shell class Basic def initialize @level = :normal end def say(message) puts message end def ask(prompt) print prompt gets.chomp end def error(message) puts "Error: #{message}" end def warn(message) puts "Warning: #{message}" end def info(message) puts message end def debug(message) puts "Debug: #{message}" if @level == :debug end end end end ``` -------------------------------- ### PubGrub Term Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a term in a PubGrub constraint, typically a package and its version constraint. ```ruby module PubGrub class Term attr_reader :package, :constraint def initialize(package, constraint) @package = package @constraint = constraint end def ==(other) other.is_a?(Term) && @package == other.package && @constraint == other.constraint end def hash [@package, @constraint].hash end def to_s "#{@package} #{@constraint}" end end end ``` -------------------------------- ### Thor Line Editor Basic Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A basic line editor implementation for Thor. ```ruby module Thor module LineEditor class Basic def initialize(prompt) @prompt = prompt end def call print @prompt gets.chomp end end end end ``` -------------------------------- ### URI File Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Handles file-specific URI schemes. ```ruby module URI class File < Generic # Your code goes here... end end ``` -------------------------------- ### PubGrub Incompatibility Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents an incompatibility between package versions in PubGrub. ```ruby module PubGrub class Incompatibility attr_reader :terms def initialize(terms) @terms = terms.sort_by(&:to_s) end def ==(other) other.is_a?(Incompatibility) && @terms == other.terms end def hash @terms.hash end def to_s @terms.join(" or ") end end end ``` -------------------------------- ### PubGrub Solve Failure Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Represents a failure to find a solution during PubGrub dependency resolution. ```ruby module PubGrub class SolveFailure < StandardError attr_reader :incompatibilities def initialize(incompatibilities) @incompatibilities = incompatibilities super(incompatibilities.map(&:to_s).join(", ")) end end end ``` -------------------------------- ### Upgrade RubyGems Source: https://github.com/ruby/rubygems/blob/master/README.md Upgrade to the latest version of RubyGems by running the `gem update --system` command. ```bash $ gem update --system ``` -------------------------------- ### Thor Actions: Create Link Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Action for creating a symbolic link. ```ruby module Thor module Actions class CreateLink < Base def initialize(file, target, config = {}) # rubocop:disable Metrics/ParameterLists super(config) @file = file @target = target @config = config end def invoke! create_link(@target, @file, @config) end def undo! remove_file(@file, @config) end end end end ``` -------------------------------- ### Minitest Template for Newgem Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt This is a Minitest template used for generating new gems. It sets up a basic test structure. ```ruby require "minitest/autorun" class NewgemTest < Minitest::Test def test_that_it_works assert_equal 42, Newgem.new.the_answer end end ``` -------------------------------- ### Net::HTTP::Persistent Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Provides a persistent HTTP client that reuses connections. ```ruby module Net module HTTP class Persistent # Your code goes here... end end end ``` -------------------------------- ### FileUtils Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A Ruby library providing utility methods for file operations. ```ruby module FileUtils # Your code goes here... end ``` -------------------------------- ### Release RubyGems Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Executes the full release process for RubyGems, including packaging, tagging, and uploading artifacts. ```bash bin/rake release ``` -------------------------------- ### Bash Alias for Local Bundler Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Create a convenient shell alias in your Bash configuration to run Bundler directly from your local clone. ```bash alias dbundle='ruby /[repo root]/bin/bundle' ``` -------------------------------- ### Run Bundler Specs in Parallel Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute multiple Bundler spec files, or long-running specs, in parallel for faster feedback. This is also used in CI. ```ruby bin/parallel_rspec spec/install ``` -------------------------------- ### URI Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Provides classes for working with Uniform Resource Identifiers (URIs). ```ruby require "uri" ``` -------------------------------- ### Connection Pool Wrapper Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A wrapper class for managing connections within the Connection Pool. ```ruby module ConnectionPool class Wrapper def initialize(size = 5, &block) @pool = TimedStack.new @size = size @block = block @mutex = Mutex.new end def with yield pop ensure push pop end def pop @mutex.synchronize do @pool.pop || ConnectionPool.new(&@block).tap do |conn| @pool.push conn end end end def push(conn) @pool.push conn end end end ``` -------------------------------- ### Run Individual RubyGems Test File Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Execute a specific test file within the RubyGems test suite. ```ruby bin/test-unit test/rubygems/test_deprecate.rb ``` -------------------------------- ### Connection Pool Library Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Provides a thread-safe connection pool for managing external resources. ```ruby module ConnectionPool # Your code goes here... end ``` -------------------------------- ### Print Debugging in Ruby Source: https://github.com/ruby/rubygems/blob/master/doc/DEBUGGING.md Use `puts` statements to inspect variables and execution flow during debugging. This is helpful for understanding the state of your code, especially when running tests. ```ruby puts "stacktrace: #{caller_locations(0).join("\n")}" puts "@definition: #{@definition}" puts "specification.class.name: #{specification.class.name}" puts "spec.method(:to_checksum).source_location: #{spec.method(:to_checksum).source_location}" # etc ``` -------------------------------- ### Check RubyGems Code Style Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Verify that your code adheres to the project's code style guidelines using RuboCop. ```ruby bin/rake rubocop ``` -------------------------------- ### Upgrade Rubygems Source: https://github.com/ruby/rubygems/blob/master/doc/UPGRADING.md Use this command to update Rubygems to the latest stable version. ```bash gem update --system ``` -------------------------------- ### Connection Pool Version Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Defines the version of the Connection Pool library. ```ruby module ConnectionPool VERSION = "0.1.0" end ``` -------------------------------- ### Thor Actions: Inject Into File Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Action for injecting content into a specific file. ```ruby module Thor module Actions class InjectToFile < FileManipulation attr_reader :content, :before, :after def initialize(file, content, config = {}) # rubocop:disable Metrics/ParameterLists super(file, config) @content = content @before = config[:before] @after = config[:after] end def invoke! inject_into_file(@file, @content, @config) end def undo! # This is tricky. We need to remove the content that was injected. # For simplicity, we'll just remove the file if it was created. # A more robust solution would involve tracking the exact lines added. remove_file(@file, @config) if @config[:force] end end end end ``` -------------------------------- ### Net::HTTP::Persistent Connection Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Manages individual persistent HTTP connections. ```ruby module Net module HTTP class Persistent class Connection # Your code goes here... end end end end ``` -------------------------------- ### URI FTP Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Handles FTP-specific URI schemes. ```ruby module URI class FTP < Generic # Your code goes here... end end ``` -------------------------------- ### Thor Actions: File Manipulation Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Base class for file manipulation actions in Thor. ```ruby module Thor module Actions class FileManipulation < Base attr_reader :file, :config def initialize(file, config = { verbose: true }) super(config) @file = file @config = config end def invoke! raise NotImplementedError end def undo! raise NotImplementedError end end end end ``` -------------------------------- ### Bundler UI Shell Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt The default Bundler UI handler, responsible for displaying messages to the user in a shell environment. ```ruby module Bundler module UI class Shell attr_accessor :level def initialize @level = :normal end def confirm(msg) say "#{msg} " ask("") end def alert(msg) say_with_color "#{msg}\n", :red end def error(msg) say_with_color "#{msg}\n", :red end def warn(msg) say_with_color "#{msg}\n", :yellow end def info(msg) say "#{msg}\n" end def debug(msg) say_with_color "#{msg}\n", :gray if @level == :debug end def error_message(heading, message) error "#{heading}\n\n#{message}" end def error_list(heading, list) error "#{heading}\n\n#{list.map { |m| "* #{m}" }.join("\n")}" end def error_with_backtrace(heading, message, backtrace) error_message(heading, message) backtrace.each { |line| error " #{line}" } end def confirm_with_reason(msg, reason) say "#{msg} " ask("") say " (#{reason})\n" end def ask(msg) print msg gets.chomp end def ask_for_password(msg) print msg STDIN.getpass.chomp end def choose_from_list(msg, list) say msg list.each_with_index do |choice, i| # rubocop:disable Style/EachWithObject say "#{i.next}. #{choice}" end ask("Enter number: ").to_i end def options(opts) opts.each do |key, value| # rubocop:disable Style/EachWithObject say " --#{key} #{value}" end end def add_color(string, color) string end def trim(string) string.strip end def say_with_color(message, color, options = { newline: true }) message = message.chomp if options[:newline] puts add_color(message, color) end def say(message, options = { newline: true }) message = message.chomp if options[:newline] puts message end def print(message) $stdout.print message end def print_with_color(message, color) $stdout.print add_color(message, color) end def prompt(message) print message gets.chomp end def prompt_with_color(message, color) print_with_color message, color gets.chomp end def status(message) say "#{message}..." end def status_with_color(message, color) say_with_color "#{message}...", color end def table(hash) # no-op end def columns @columns || 80 end def columns=(columns) @columns = columns end def padding @padding || 0 end def padding=(padding) @padding = padding end def format_string(string) string end def format_table(hash) # no-op end def format_list(list) # no-op end def format_error(heading, message) # no-op end def format_error_list(heading, list) # no-op end def format_error_with_backtrace(heading, message, backtrace) # no-op end def format_confirm_with_reason(msg, reason) # no-op end def format_ask(msg) # no-op end def format_ask_for_password(msg) # no-op end def format_choose_from_list(msg, list) # no-op end def format_options(opts) # no-op end end end end ``` -------------------------------- ### Thor Runner Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Handles the execution and running of Thor commands. ```ruby module Thor class Runner def initialize(klass, shell = nil) @klass = klass @shell = shell end def run(args = ARGV) # Logic to find and execute the appropriate command end end end ``` -------------------------------- ### Thor Shell HTML Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A Thor shell implementation that outputs HTML. ```ruby module Thor module Shell class HTML < Basic def say(message) puts "

#{message}

" end def say_with_color(message, color, options = { newline: true }) # HTML formatting for color say message end end end end ``` -------------------------------- ### Add Owner to RubyGems Gem Source: https://github.com/ruby/rubygems/blob/master/doc/POLICIES.md Use this command to add a new owner to the 'bundler' gem on RubyGems.org. Replace EMAIL with the owner's email address. ```bash $ gem owner -a EMAIL bundler ``` -------------------------------- ### Test Bundler Against Specific RubyGems Versions Source: https://github.com/ruby/rubygems/blob/master/doc/GETTING_STARTED.md Test Bundler against specific versions of RubyGems by setting the RGV environment variable to the desired version tag. ```ruby RGV=v3.2.33 bin/parallel_rspec ``` -------------------------------- ### Dry Run Release Verification Source: https://github.com/ruby/rubygems/blob/master/doc/RELEASE.md Verifies the release process for RubyGems in a dry run mode before the actual release. Confirms CI passes on the release PR. ```bash DRYRUN=1 rake release ``` -------------------------------- ### URI Common Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Common utilities and base classes for the URI library. ```ruby module URI # Your code goes here... end ``` -------------------------------- ### Thor Parser Options Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Manages a collection of options for Thor commands. ```ruby module Thor module Parser class Options def initialize @options = {} end def add(name, type, desc, required, default) @options[name] = Option.new(name, type, desc, required, default) end def parse(args) # Logic to parse options from arguments end end end end ``` -------------------------------- ### Bundler UI Proxy Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt A proxy class for Bundler's UI, likely used to route output to different handlers. ```ruby module Bundler module UI class RGProxy < Shell def initialize super @level = :normal end def confirm(msg) # no-op end def alert(msg) # no-op end def error(msg) # no-op end def warn(msg) # no-op end def info(msg) # no-op end def debug(msg) # no-op end def error_message(heading, message) # no-op end def error_list(heading, list) # no-op end def error_with_backtrace(heading, message, backtrace) # no-op end def confirm_with_reason(msg, reason) # no-op end def ask(msg) # no-op end def ask_for_password(msg) # no-op end def choose_from_list(msg, list) # no-op end def options(opts) # no-op end def level=(level) @level = level end def level @level end def add_color(string, color) string end def trim(string) string end def say_with_color(message, color, options = { newline: true }) # no-op end def say(message, options = { newline: true }) # no-op end def print(message) # no-op end def print_with_color(message, color) # no-op end def prompt(message) # no-op end def prompt_with_color(message, color) # no-op end def status(message) # no-op end def status_with_color(message, color) # no-op end def table(hash) # no-op end def columns 0 end def columns=(columns) # no-op end def padding 0 end def padding=(padding) # no-op end def format_string(string) string end def format_table(hash) # no-op end def format_list(list) # no-op end def format_error(heading, message) # no-op end def format_error_list(heading, list) # no-op end def format_error_with_backtrace(heading, message, backtrace) # no-op end def format_confirm_with_reason(msg, reason) # no-op end def format_ask(msg) # no-op end def format_ask_for_password(msg) # no-op end def format_choose_from_list(msg, list) # no-op end def format_options(opts) # no-op end end end end ``` -------------------------------- ### Thor Parser Arguments Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Manages a collection of arguments for Thor commands. ```ruby module Thor module Parser class Arguments def initialize @arguments = [] end def add(name, type, desc, required, default) @arguments << Argument.new(name, type, desc, required, default) end def parse(args) # Logic to parse arguments based on defined structure end end end end ``` -------------------------------- ### Thor Util Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Utility methods used within the Thor library. ```ruby module Thor module Util # Your code goes here... end end ``` -------------------------------- ### Net::HTTP::Persistent Pool Source: https://github.com/ruby/rubygems/blob/master/Manifest.txt Manages a pool of persistent HTTP connections. ```ruby module Net module HTTP class Persistent class Pool # Your code goes here... end end end end ```