Class: Gem::Commands::CheckSourcesCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
Sources
Defined in:
lib/gem_check_sources/commands/check_sources_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sources

#currently_loaded_sources

Constructor Details

#initializeCheckSourcesCommand

Returns a new instance of CheckSourcesCommand.



12
13
14
15
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 12

def initialize
  super('check_sources', 'Check which gem sources are currently available.')
  defaults.merge!(:sources_to_add => [], :sources_to_remove => [], :verbose? => false)
end

Class Method Details

.sources_fileObject



8
9
10
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 8

def self.sources_file
  File.join(ENV['HOME'], '.gem', 'ruby', 'sources.yml')
end

Instance Method Details

#check_sourcesObject



33
34
35
36
37
38
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 33

def check_sources        
  sources.unchecked.concat(currently_loaded_sources)
  sources.verify
  sources.sync
  sources.dump(CheckSourcesCommand.sources_file)
end

#executeObject



17
18
19
20
21
22
23
24
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 17

def execute
  if File.exist?(CheckSourcesCommand.sources_file)  
    check_sources
  else
    initialize_sources
  end
  list
end

#initialize_sourcesObject



26
27
28
29
30
31
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 26

def initialize_sources
  @sources = List.new(:unchecked => currently_loaded_sources)
  @sources.verify
  @sources.sync
  @sources.dump(CheckSourcesCommand.sources_file)
end

#listObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gem_check_sources/commands/check_sources_command.rb', line 40

def list
  puts "*** CURRENT SOURCES ***"
  puts ""
  puts "** ACTIVE SOURCES **"
  puts ""
  sources.active.each { |source| puts source }
  puts ""
  puts "** INACTIVE SOURCES **"
  puts ""
  sources.inactive.each { |source| puts source }
end