Class: Kward::UpdateCheck
- Inherits:
-
Object
- Object
- Kward::UpdateCheck
- Defined in:
- lib/kward/update_check.rb
Overview
Cached RubyGems update check for the interactive startup screen.
Defined Under Namespace
Classes: Notice
Constant Summary collapse
- CHECK_INTERVAL_SECONDS =
24 * 60 * 60
- LATEST_VERSION_URL =
URI("https://rubygems.org/api/v1/versions/kward/latest.json")
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(current_version:, config: ConfigFiles.read_config, path: ConfigFiles.update_check_cache_path, now: Time.now) ⇒ UpdateCheck
constructor
A new instance of UpdateCheck.
- #notice ⇒ Object
- #refresh ⇒ Object
- #refresh_if_stale ⇒ Object
Constructor Details
#initialize(current_version:, config: ConfigFiles.read_config, path: ConfigFiles.update_check_cache_path, now: Time.now) ⇒ UpdateCheck
Returns a new instance of UpdateCheck.
16 17 18 19 20 21 |
# File 'lib/kward/update_check.rb', line 16 def initialize(current_version:, config: ConfigFiles.read_config, path: ConfigFiles.update_check_cache_path, now: Time.now) @current_version = current_version.to_s @config = config @path = path @now = now end |
Instance Method Details
#enabled? ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/kward/update_check.rb', line 23 def enabled? return false if disabled_by_environment? updates = @config["updates"] return false if updates.is_a?(Hash) && updates["check"] == false true end |
#notice ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kward/update_check.rb', line 32 def notice return nil unless enabled? latest_version = cache["latest_version"].to_s return nil if latest_version.empty? return nil if dismissed_version == latest_version return nil unless newer_than_current?(latest_version) Notice.new(latest_version: latest_version) end |
#refresh ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kward/update_check.rb', line 50 def refresh latest_version = fetch_latest_version write_cache(cache.merge( "checked_at" => @now.utc.iso8601, "latest_version" => latest_version )) true rescue StandardError false end |
#refresh_if_stale ⇒ Object
43 44 45 46 47 48 |
# File 'lib/kward/update_check.rb', line 43 def refresh_if_stale return false unless enabled? return false unless stale? refresh end |