模块 Gem::UpdateSuggestion
用于 Gem::Command
的混入方法,以推广可用的 RubyGems 更新
常量
- ONE_WEEK
公共实例方法
eligible_for_update?() 点击以切换源代码
确定当前环境是否适合更新建议。
# File rubygems/update_suggestion.rb, line 24 def eligible_for_update? # explicit opt-out return false if Gem.configuration[:prevent_update_suggestion] return false if ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] # focus only on human usage of final RubyGems releases return false unless Gem.ui.tty? return false if Gem.rubygems_version.prerelease? return false if Gem.disable_system_update_message return false if Gem::CIDetector.ci? # check makes sense only when we can store timestamp of last try # otherwise we will not be able to prevent "annoying" update message # on each command call return unless Gem.configuration.state_file_writable? # load time of last check, ensure the difference is enough to repeat the suggestion check_time = Time.now.to_i last_update_check = Gem.configuration.last_update_check return false if (check_time - last_update_check) < ONE_WEEK # compare current and latest version, this is the part where # latest rubygems spec is fetched from remote (Gem.rubygems_version < Gem.latest_rubygems_version).tap do |eligible| # store the time of last successful check into state file Gem.configuration.last_update_check = check_time return eligible end rescue StandardError # don't block install command on any problem false end
update_suggestion() 点击以切换源代码
用于推广可用的 RubyGems 更新的消息,以及相关的 gem 更新命令。
# File rubygems/update_suggestion.rb, line 12 def update_suggestion <<-MESSAGE A new release of RubyGems is available: #{Gem.rubygems_version} → #{Gem.latest_rubygems_version}! Run `gem update --system #{Gem.latest_rubygems_version}` to update your installation. MESSAGE end