Module: OneGadget::Update

Defined in:
lib/one_gadget/update.rb

Overview

For automatically check update.

Constant Summary collapse

FREQUENCY =

At least 30 days between check for new version.

30 * 24 * 60 * 60
CACHE_FILE =

Path to cache file.

File.join(ENV.fetch('HOME', Dir.tmpdir), '.cache', 'one_gadget', 'update').freeze

Class Method Summary collapse

Class Method Details

.check!void

This method returns an undefined value.

Check if new releases have been drafted.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/one_gadget/update.rb', line 21

def check!
  return unless need_check?

  FileUtils.touch(cache_file)
  OneGadget::Logger.info("Checking for new versions of OneGadget\n" \
                         "To disable this functionality, do\n$ echo never > #{CACHE_FILE}\n\n")
  latest = Helper.latest_tag[1..-1] # remove 'v'
  if Gem::Version.new(latest) <= Gem::Version.new(OneGadget::VERSION)
    return OneGadget::Logger.info("You have the latest version of OneGadget (#{latest})!\n\n")
  end

  # show update message
  msg = format('A newer version of OneGadget is available (%s --> %s).', OneGadget::VERSION, latest)
  OneGadget::Logger.ask_update(msg: msg)
end