Sha256: 7ba7ea1c3ada60ff8d5e82398f5e011f0eb28ef9f6082420e7c8c6aa8ca978ef

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

require 'open-uri'

module Produce
  # Verifies, the user runs the latest version of this gem
  class UpdateChecker
    # This method will check if the latest version is installed and show a warning if that's not the case
    def self.verify_latest_version
      if self.update_available?
        v = fetch_latest
        puts '#######################################################################'.green
        puts "# produce #{v} is available.".green
        puts "# It is recommended to use the latest version.".green
        puts "# Update using '(sudo) gem update produce'.".green
        puts "# To see what's new, open https://github.com/KrauseFx/produce/releases.".green
        puts '#######################################################################'.green
        return true
      end
      false
    end

    # Is a new official release available (this does not include pre-releases)
    def self.update_available?
      begin
        latest = fetch_latest
        if latest and Gem::Version.new(latest) > Gem::Version.new(current_version)
          return true
        end
      rescue => ex
        Helper.log.error("Could not check if 'produce' is up to date.")
      end
      return false
    end

    # The currently used version of this gem
    def self.current_version
      Produce::VERSION
    end

    private
      def self.fetch_latest
        JSON.parse(open("http://rubygems.org/api/v1/gems/produce.json").read)["version"]
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
produce-0.1.3 lib/produce/update_checker.rb
produce-0.1.2 lib/produce/update_checker.rb
produce-0.1.1 lib/produce/update_checker.rb