Class: Dotsync::VersionChecker
- Inherits:
-
Object
- Object
- Dotsync::VersionChecker
- Includes:
- XDGBaseDirectory
- Defined in:
- lib/dotsync/utils/version_checker.rb
Constant Summary collapse
- RUBYGEMS_API_URL =
"https://rubygems.org/api/v1/versions/dotsync/latest.json"- CHECK_INTERVAL =
24 hours in seconds
86400- REQUEST_TIMEOUT =
seconds
3
Instance Method Summary collapse
-
#check_for_updates ⇒ Object
Main method to check for updates and display message if needed.
-
#initialize(current_version, logger: nil) ⇒ VersionChecker
constructor
A new instance of VersionChecker.
-
#should_check? ⇒ Boolean
Returns true if we should check for updates (cache expired or doesn’t exist).
Methods included from XDGBaseDirectory
#xdg_bin_home, #xdg_cache_home, #xdg_config_home, #xdg_data_home
Constructor Details
#initialize(current_version, logger: nil) ⇒ VersionChecker
Returns a new instance of VersionChecker.
16 17 18 19 |
# File 'lib/dotsync/utils/version_checker.rb', line 16 def initialize(current_version, logger: nil) @current_version = current_version @logger = logger end |
Instance Method Details
#check_for_updates ⇒ Object
Main method to check for updates and display message if needed
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dotsync/utils/version_checker.rb', line 34 def check_for_updates return unless should_check? latest_version = fetch_latest_version return unless latest_version update_cache (latest_version) if version_outdated?(@current_version, latest_version) rescue => e # Silently fail - never break the application debug_log("Error checking for updates: #{e.}") end |
#should_check? ⇒ Boolean
Returns true if we should check for updates (cache expired or doesn’t exist)
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dotsync/utils/version_checker.rb', line 22 def should_check? return false if ENV["DOTSYNC_NO_UPDATE_CHECK"] return true unless File.exist?(cache_file_path) Time.now - last_check_time > CHECK_INTERVAL rescue => e # If we can't determine, be conservative and don't check debug_log("Error checking if should check: #{e.}") false end |