Class: Captive::UpdateChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/captive/update_checker.rb

Constant Summary collapse

VERSION_ENDPOINT =
"https://raw.githubusercontent.com/captive-studio/homebrew-tap/main/version.json"
CACHE_TTL =

24h en secondes

86_400

Instance Method Summary collapse

Constructor Details

#initialize(http: HttpClient.new, cache_path: default_cache_path, current_version: VERSION) ⇒ UpdateChecker

Returns a new instance of UpdateChecker.



14
15
16
17
18
# File 'lib/captive/update_checker.rb', line 14

def initialize(http: HttpClient.new, cache_path: default_cache_path, current_version: VERSION)
  @http            = http
  @cache_path      = cache_path
  @current_version = Gem::Version.new(current_version)
end

Instance Method Details

#check ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/captive/update_checker.rb', line 20

def check
  data   = fetch_version_data
  latest  = Gem::Version.new(data["latest"])
  minimum = Gem::Version.new(data["minimum"])

  return :blocked           if @current_version < minimum
  return :update_available  if @current_version < latest

  :up_to_date
rescue StandardError
  :up_to_date
end