class Gem::Commands::SourcesCommand - Documentation for Ruby 4.0
Description: Documentation for the Gem::Commands::SourcesCommand class
Keywords: ruby,class,Gem::Commands::SourcesCommand

🔍

No recent searches

# class Gem::Commands::SourcesCommand

### Public Class Methods

new ()
Source

    # File lib/rubygems/commands/sources_command.rb, line 11
    def initialize
      require "fileutils"

      super "sources",
            "Manage the sources and cache file RubyGems uses to search for gems"

      add_option "-a", "--add SOURCE_URI", "Add source" do |value, options|
        options[:add] = value
      end

      add_option "--append SOURCE_URI", "Append source (can be used multiple times)" do |value, options|
        options[:append] = value
      end

      add_option "-p", "--prepend SOURCE_URI", "Prepend source (can be used multiple times)" do |value, options|
        options[:prepend] = value
      end

      add_option "-l", "--list", "List sources" do |value, options|
        options[:list] = value
      end

      add_option "-r", "--remove SOURCE_URI", "Remove source" do |value, options|
        options[:remove] = value
      end

      add_option "-c", "--clear-all", "Remove all sources (clear the cache)" do |value, options|
        options[:clear_all] = value
      end

      add_option "-u", "--update", "Update source cache" do |value, options|
        options[:update] = value
      end

      add_option "-f", "--[no-]force", "Do not show any confirmation prompts and behave as if 'yes' was always answered" do |value, options|
        options[:force] = value
      end

      add_proxy_option
    end

Calls superclass method `Gem::Command::new`

### Public Instance Methods

check_typo_squatting (source)
Source

    # File lib/rubygems/commands/sources_command.rb, line 123
      def check_typo_squatting(source)
        if source.typo_squatting?("rubygems.org")
          question = <<-QUESTION.chomp
    #{source.uri} is too similar to https://rubygems.org

    Do you want to add this source?
          QUESTION

          terminate_interaction 1 unless options[:force] || ask_yes_no(question)
        end
      end

execute ()
Source

    # File lib/rubygems/commands/sources_command.rb, line 263
    def execute
      clear_all if options[:clear_all]

      add_source options[:add] if options[:add]

      prepend_source options[:prepend] if options[:prepend]

      append_source options[:append] if options[:append]

      remove_source options[:remove] if options[:remove]

      update if options[:update]

      list if list?
    end

### Private Instance Methods

build_new_source (source_uri)
Source

    # File lib/rubygems/commands/sources_command.rb, line 342
    def build_new_source(source_uri)
      source = build_source(source_uri)
      check_rubygems_https(source.uri.to_s)
      check_typo_squatting(source)
      source
    end

build_source (source_uri)
Source

    # File lib/rubygems/commands/sources_command.rb, line 337
    def build_source(source_uri)
      source_uri = normalize_source_uri(source_uri)
      Gem::Source.new(source_uri)
    end

config_file_name ()
Source

    # File lib/rubygems/commands/sources_command.rb, line 333
    def config_file_name
      Gem.configuration.config_file_name
    end

configured_sources ()
Source

    # File lib/rubygems/commands/sources_command.rb, line 326
    def configured_sources
      return @configured_sources if defined?(@configured_sources)

      configuration_sources = Gem.configuration.sources
      @configured_sources = Gem::SourceList.from(configuration_sources) if configuration_sources
    end

default_sources ()
Source

    # File lib/rubygems/commands/sources_command.rb, line 322
    def default_sources
      Gem::SourceList.from(Gem.default_sources)
    end