Module: Gem::UpdateSuggestion
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubygems/update_suggestion.rb |
Overview
Mixin methods for Command
to promote available RubyGems update
Constant Summary
-
CI_ENV_VARS =
list taken from github.com/watson/ci-info/blob/7a3c30d/index.js#L56-L66
[ "CI", # Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari "CONTINUOUS_INTEGRATION", # Travis CI, Cirrus CI "BUILD_NUMBER", # Jenkins, TeamCity "CI_APP_ID", "CI_BUILD_ID", "CI_BUILD_NUMBER", # Applfow "RUN_ID" # TaskCluster, dsari ].freeze
-
ONE_WEEK =
# File 'lib/rubygems/update_suggestion.rb', line 167 * 24 * 60 * 60
Instance Attribute Summary
- #ci? ⇒ Boolean readonly
-
#eglible_for_update? ⇒ Boolean
readonly
Determines if current environment is eglible for update suggestion.
Instance Method Summary
-
#update_suggestion
Message to promote available RubyGems update with related gem update command.
Instance Attribute Details
#ci? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rubygems/update_suggestion.rb', line 66
def ci? CI_ENV_VARS.any? {|var| ENV.include?(var) } end
#eglible_for_update? ⇒ Boolean
(readonly)
Determines if current environment is eglible for update suggestion.
# File 'lib/rubygems/update_suggestion.rb', line 33
def eglible_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. return false if 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 |eglible| # store the time of last successful check into state file Gem.configuration.last_update_check = check_time return eglible end rescue # don't block install command on any problem false end
Instance Method Details
#update_suggestion
Message to promote available RubyGems update with related gem update command.
# File 'lib/rubygems/update_suggestion.rb', line 21
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