class CC::CLI::VersionChecker
Constants
- DEFAULT_VERSIONS_URL
- VERSION_CHECK_TIMEOUT
Public Instance Methods
check()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 12 def check return unless global_config.check_version? && version_check_is_due? print_new_version_message if outdated? global_config.save rescue => error CLI.logger.debug(error) end
Private Instance Methods
api_response()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 40 def api_response @api_response ||= begin cache! JSON.parse(api_response_body) rescue JSON::ParserError => error CLI.logger.debug(error) { "outdated" => false, } end end
api_response_body()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 52 def api_response_body if http_response.is_a? Net::HTTPSuccess http_response.body else raise Net::HTTPFatalError.new("HTTP Error", http_response) end rescue Net::HTTPFatalError => error CLI.logger.debug(error) "" end
cache!(data)
click to toggle source
# File lib/cc/cli/version_checker.rb, line 79 def cache!(data) global_cache.latest_version = data["latest"] global_cache.outdated = data["outdated"] == true global_cache.last_version_check = Time.now data end
global_cache()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 98 def global_cache @global_cache ||= GlobalCache.new end
global_config()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 94 def global_config @global_config ||= GlobalConfig.new end
http_response()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 63 def http_response @http_response ||= begin uri = URI.parse(ENV.fetch("CODECLIMATE_VERSIONS_URL", DEFAULT_VERSIONS_URL)) uri.query = { version: version, uid: global_config.uuid }.to_query http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = 5 http.read_timeout = 5 http.ssl_timeout = 5 http.use_ssl = uri.scheme == "https" http.get(uri, "User-Agent" => user_agent) end end
latest_version()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 32 def latest_version api_response["latest"] end
outdated?()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 28 def outdated? api_response["outdated"] end
print_new_version_message()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 36 def print_new_version_message warn "A new version (v#{latest_version}) is available. Upgrade instructions are available at: https://github.com/codeclimate/codeclimate#packages" end
terminal()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 102 def terminal @terminal ||= HighLine.new(nil, $stderr) end
user_agent()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 90 def user_agent "Code Climate CLI #{version}" end
version()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 86 def version @version ||= Version.new.version end
version_check_is_due?()
click to toggle source
# File lib/cc/cli/version_checker.rb, line 24 def version_check_is_due? Time.now > global_cache.last_version_check + VERSION_CHECK_TIMEOUT end