Class: LibGems::Commands::UpdateCommand
- Inherits:
-
LibGems::Command
- Object
- LibGems::Command
- LibGems::Commands::UpdateCommand
- Includes:
- InstallUpdateOptions, LocalRemoteOptions, VersionOption
- Defined in:
- lib/libgems/commands/update_command.rb
Instance Attribute Summary
Attributes inherited from LibGems::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ UpdateCommand
constructor
A new instance of UpdateCommand.
- #update_gem(name, version = LibGems::Requirement.default) ⇒ Object
- #update_gems(gems_to_update) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
- #which_to_update(highest_installed_gems, gem_names) ⇒ Object
Methods included from VersionOption
#add_platform_option, #add_prerelease_option, #add_version_option
Methods included from LocalRemoteOptions
#accept_uri_http, #add_bulk_threshold_option, #add_local_remote_options, #add_proxy_option, #add_source_option, #add_update_sources_option, #both?, #local?, #remote?
Methods included from InstallUpdateOptions
#add_install_update_options, #install_update_defaults_str
Methods inherited from LibGems::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, #description, extra_args, extra_args=, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ UpdateCommand
Returns a new instance of UpdateCommand.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/libgems/commands/update_command.rb', line 15 def initialize super 'update', 'Update the named gems (or all installed gems) in the local repository', :generate_rdoc => true, :generate_ri => true, :force => false, :test => false OptionParser.accept LibGems::Version do |value| LibGems::Version.new value value end add_platform_option add_prerelease_option "as update targets" end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/libgems/commands/update_command.rb', line 36 def arguments # :nodoc: "GEMNAME name of gem to update" end |
#defaults_str ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/libgems/commands/update_command.rb', line 40 def defaults_str # :nodoc: "--rdoc --ri --no-force --no-test --install-dir #{LibGems.dir}" end |
#execute ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/libgems/commands/update_command.rb', line 48 def execute @installer = LibGems::DependencyInstaller.new @updated = [] hig = {} say "Updating installed gems" hig = {} # highest installed gems LibGems.source_index.each do |name, spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version then hig[spec.name] = spec end end gems_to_update = which_to_update hig, [:args] updated = update_gems gems_to_update if updated.empty? then say "Nothing to update" else say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}" if [:generate_ri] then updated.each do |gem| LibGems::DocManager.new(gem, [:rdoc_args]).generate_ri end LibGems::DocManager.update_ri_cache end if [:generate_rdoc] then updated.each do |gem| LibGems::DocManager.new(gem, [:rdoc_args]).generate_rdoc end end end end |
#update_gem(name, version = LibGems::Requirement.default) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/libgems/commands/update_command.rb', line 89 def update_gem name, version = LibGems::Requirement.default return if @updated.any? { |spec| spec.name == name } success = false say "Updating #{name}" begin @installer.install name, version success = true rescue LibGems::InstallError => e alert_error "Error installing #{name}:\n\t#{e.}" success = false end @installer.installed_gems.each do |spec| @updated << spec say "Successfully installed #{spec.full_name}" if success end end |
#update_gems(gems_to_update) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/libgems/commands/update_command.rb', line 108 def update_gems gems_to_update gems_to_update.uniq.sort.each do |name| update_gem name end @updated end |
#usage ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/libgems/commands/update_command.rb', line 44 def usage # :nodoc: "#{program_name} GEMNAME [GEMNAME ...]" end |
#which_to_update(highest_installed_gems, gem_names) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/libgems/commands/update_command.rb', line 116 def which_to_update(highest_installed_gems, gem_names) result = [] highest_installed_gems.each do |l_name, l_spec| next if not gem_names.empty? and gem_names.all? { |name| /#{name}/ !~ l_spec.name } dependency = LibGems::Dependency.new l_spec.name, "> #{l_spec.version}" begin fetcher = LibGems::SpecFetcher.fetcher spec_tuples = fetcher.find_matching dependency rescue LibGems::RemoteFetcher::FetchError => e raise unless fetcher.warn_legacy e do require 'libgems/source_info_cache' dependency.name = '' if dependency.name == // specs = LibGems::SourceInfoCache.search_with_source dependency spec_tuples = specs.map do |spec, source_uri| [[spec.name, spec.version, spec.original_platform], source_uri] end end end matching_gems = spec_tuples.select do |(name, _, platform),| name == l_name and LibGems::Platform.match platform end highest_remote_gem = matching_gems.sort_by do |(_, version),| version end.last if highest_remote_gem and l_spec.version < highest_remote_gem.first[1] then result << l_name end end result end |