Class: Gem::UpdateCommand
- Includes:
- InstallUpdateOptions
- Defined in:
- lib/rubygems/gem_commands.rb
Instance Attribute Summary
Attributes inherited from Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
- #arguments ⇒ Object
- #defaults_str ⇒ Object
- #do_rubygems_update(version_string) ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ UpdateCommand
constructor
A new instance of UpdateCommand.
- #which_to_update(highest_installed_gems, remote_gemspecs) ⇒ Object
Methods included from InstallUpdateOptions
#add_install_update_options, #install_update_defaults_str
Methods inherited from Command
add_common_option, #add_option, add_specific_extra_args, common_options, extra_args, extra_args=, #handles?, #invoke, #merge_options, #remove_option, #show_help, specific_extra_args, specific_extra_args_hash, #usage, #when_invoked
Methods included from DefaultUserInteraction
#ui, ui, #ui=, ui=, #use_ui, use_ui
Constructor Details
#initialize ⇒ UpdateCommand
Returns a new instance of UpdateCommand.
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 |
# File 'lib/rubygems/gem_commands.rb', line 925 def initialize super( 'update', 'Update the named gem (or all installed gems) in the local repository', { :generate_rdoc => true, :generate_ri => true, :force => false, :test => false, :install_dir => Gem.dir }) add_option('--system', 'Update the RubyGems system software') do |value, | [:system] = value end end |
Instance Method Details
#arguments ⇒ Object
948 949 950 |
# File 'lib/rubygems/gem_commands.rb', line 948 def arguments "GEMNAME(s) name of gem(s) to update" end |
#defaults_str ⇒ Object
943 944 945 946 |
# File 'lib/rubygems/gem_commands.rb', line 943 def defaults_str "--rdoc --ri --no-force --no-test\n" + "--install-dir #{Gem.dir}" end |
#do_rubygems_update(version_string) ⇒ Object
998 999 1000 1001 1002 1003 1004 |
# File 'lib/rubygems/gem_commands.rb', line 998 def do_rubygems_update(version_string) update_dir = File.join(Gem.dir, "gems", "rubygems-update-#{version_string}") Dir.chdir(update_dir) do puts "Installing RubyGems #{version_string}" system "#{Gem.ruby} setup.rb" end end |
#execute ⇒ Object
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 |
# File 'lib/rubygems/gem_commands.rb', line 952 def execute if [:system] say "Updating RubyGems..." if ! [:args].empty? fail "No gem names are allowed with the --system option" end [:args] = ["rubygems-update"] else say "Updating installed gems..." end hig = highest_installed_gems = {} Gem::SourceIndex.from_installed_gems.each do |name, spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version hig[spec.name] = spec end end remote_gemspecs = Gem::SourceInfoCache.search(//) gems_to_update = if([:args].empty?) then which_to_update(highest_installed_gems, remote_gemspecs) else [:args] end [:domain] = :remote # install from remote source install_command = command_manager['install'] gems_to_update.uniq.sort.each do |name| say "Attempting remote update of #{name}" [:args] = [name] install_command.() install_command.execute end if gems_to_update.include?("rubygems-update") latest_ruby_gem = remote_gemspecs.select { |s| s.name == 'rubygems-update' }.sort_by { |s| s.version }.last say "Updating version of RubyGems to #{latest_ruby_gem.version}" do_rubygems_update(latest_ruby_gem.version.to_s) end if([:system]) then say "RubyGems system software updated" else say "Gems: [#{gems_to_update.uniq.sort.collect{|g| g.to_s}.join(', ')}] updated" end end |
#which_to_update(highest_installed_gems, remote_gemspecs) ⇒ Object
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/rubygems/gem_commands.rb', line 1006 def which_to_update(highest_installed_gems, remote_gemspecs) result = [] highest_installed_gems.each do |l_name, l_spec| highest_remote_gem = remote_gemspecs.select { |spec| spec.name == l_name }. sort_by { |spec| spec.version }. last if highest_remote_gem and l_spec.version < highest_remote_gem.version result << l_name end end result end |