Class: UpdateChecker
Instance Method Summary
collapse
#escape_globs, #find_config, #find_config_file, #global_config, #global_config_location, #global_config_save, #globs_for_config
Constructor Details
9
10
11
|
# File 'lib/update_check.rb', line 9
def initialize
@config = global_config
end
|
Instance Method Details
#check_and_warn(update_enforced = true) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/update_check.rb', line 47
def check_and_warn(update_enforced = true)
now = DateTime.now
@config['update_last_check'] = now.iso8601(9)
global_config_save(@config)
check = docker_sync_update_check
if check.update_available
say_status 'warning',"There is an update (#{check.latest_version}) available (current version #{check.current_version}). Please update before you continue",:yellow
if yes?("Shall i update docker-sync to #{check.latest_version} for you?")
system('gem update docker-sync')
else
exit 1 if update_enforced
end
end
end
|
#docker_sync_update_check ⇒ Object
40
41
42
43
44
45
|
# File 'lib/update_check.rb', line 40
def docker_sync_update_check
gem_name = 'docker-sync'
current_version = get_current_version
checker = GemUpdateChecker::Client.new(gem_name, current_version)
return checker
end
|
#get_current_version ⇒ Object
35
36
37
38
|
# File 'lib/update_check.rb', line 35
def get_current_version
path = File.expand_path('../../', __FILE__)
return File.read("#{path}/VERSION")
end
|
#run ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/update_check.rb', line 13
def run
unless @config['update_check']
say_status 'hint','Skipping up-to-date check since it has been disabled in yout ~/.docker-sync-global.yml configuration',:yellow
return
end
unless should_run
return
end
check_and_warn(@config['update_enforce'])
end
|
#should_run ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/update_check.rb', line 24
def should_run
now = DateTime.now
last_check = DateTime.iso8601(@config['update_last_check'])
check_after_days = 2
if now - last_check > check_after_days
return true
end
return false
end
|