class BBFlow::Updater
Constants
- CHECK_INTERVAL
Public Class Methods
ensure_up_to_date!()
click to toggle source
@return [void]
# File lib/bb_flow/updater.rb, line 9 def ensure_up_to_date! return if recently_checked? || !update_available? if Printer.simple_question("An update from #{current_version} to #{latest_version} is available. Should I install it?") command = "gem install bb-flow -v '#{latest_version}'" puts "Executing `#{command}`..." `#{command}` exit Printer.success("Hooray, the new version has been installed! You can find the changes here: https://github.com/brightbytes/bb-flow/blob/master/CHANGELOG.md") end rescue StandardError => exception Printer.error("An error occurred while trying to self-update the gem: #{exception.message}") ensure update_last_check_unixtime! end
Private Class Methods
current_version()
click to toggle source
@return [Gem::Version]
# File lib/bb_flow/updater.rb, line 39 def current_version Gem::Version.new(BBFlow::VERSION) end
dependency()
click to toggle source
@return [Gem::Dependency]
# File lib/bb_flow/updater.rb, line 49 def dependency Gem::Dependency.new('bb-flow') end
fetcher()
click to toggle source
@return [Gem::SpecFetcher]
# File lib/bb_flow/updater.rb, line 44 def fetcher Gem::SpecFetcher.new(Gem::SourceList.from(['https://rubygems.org/'])) end
last_check_unixtime()
click to toggle source
# File lib/bb_flow/updater.rb, line 59 def last_check_unixtime 0 end
latest_version()
click to toggle source
@return [Gem::Version]
# File lib/bb_flow/updater.rb, line 34 def latest_version fetcher.search_for_dependency(dependency).first.map { |n, _| n.version }.first || Gem::Version.new('0') end
recently_checked?()
click to toggle source
@return [Boolean]
# File lib/bb_flow/updater.rb, line 54 def recently_checked? last_check_unixtime + CHECK_INTERVAL > Time.now.to_i end
update_available?()
click to toggle source
@return [Boolean]
# File lib/bb_flow/updater.rb, line 28 def update_available? puts "Looking for updates..." latest_version > current_version end
update_last_check_unixtime!()
click to toggle source
@return [void]
# File lib/bb_flow/updater.rb, line 64 def update_last_check_unixtime! Persistent::Store.get(:global).transaction { |store| store['updater']['last_check_unixtime'] = Time.now.to_i } end