In Files

  • ruby-3.1.2/lib/rubygems/commands/sources_command.rb

Files

Class/Module Index [+]

Quicksearch

Gem::Commands::SourcesCommand

Public Class Methods

new() click to toggle source
 
               # File ruby-3.1.2/lib/rubygems/commands/sources_command.rb, line 10
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 '-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
            

Public Instance Methods

check_typo_squatting(source) click to toggle source
 
               # File ruby-3.1.2/lib/rubygems/commands/sources_command.rb, line 70
  def check_typo_squatting(source)
    if source.typo_squatting?("rubygems.org")
      question = <<-QUESTION.chomp
#{source.uri.to_s} 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() click to toggle source
 
               # File ruby-3.1.2/lib/rubygems/commands/sources_command.rb, line 181
def execute
  clear_all if options[:clear_all]

  source_uri = options[:add]
  add_source source_uri if source_uri

  source_uri = options[:remove]
  remove_source source_uri if source_uri

  update if options[:update]

  list if list?
end