Class: RubynCode::CLI::VersionCheck
- Inherits:
-
Object
- Object
- RubynCode::CLI::VersionCheck
- Defined in:
- lib/rubyn_code/cli/version_check.rb
Overview
Non-blocking version check against RubyGems. Runs in a background thread so it never delays startup. Caches the result for 24 hours to avoid hammering the API.
Constant Summary collapse
- RUBYGEMS_API =
'https://rubygems.org/api/v1/versions/rubyn-code/latest.json'- CACHE_FILE =
File.join(Config::Defaults::HOME_DIR, '.version_check')
- CACHE_TTL =
24 hours
86_400
Instance Method Summary collapse
-
#initialize(renderer:) ⇒ VersionCheck
constructor
A new instance of VersionCheck.
-
#notify(timeout: 2) ⇒ Object
Waits briefly for the check to finish and prints a message if outdated.
-
#start ⇒ Object
Kicks off a background check.
Constructor Details
#initialize(renderer:) ⇒ VersionCheck
Returns a new instance of VersionCheck.
16 17 18 19 |
# File 'lib/rubyn_code/cli/version_check.rb', line 16 def initialize(renderer:) @renderer = renderer @thread = nil end |
Instance Method Details
#notify(timeout: 2) ⇒ Object
Waits briefly for the check to finish and prints a message if outdated.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubyn_code/cli/version_check.rb', line 30 def notify(timeout: 2) return unless @thread @thread.join(timeout) return unless @result return unless newer?(@result, RubynCode::VERSION) @renderer.warning( "Update available: #{RubynCode::VERSION} -> #{@result} " \ '(gem install rubyn-code)' ) end |
#start ⇒ Object
Kicks off a background check. Call ‘notify` later to display results.
22 23 24 25 26 27 |
# File 'lib/rubyn_code/cli/version_check.rb', line 22 def start return if ENV['RUBYN_NO_UPDATE_CHECK'] @thread = Thread.new { check } @thread.abort_on_exception = false end |