Sha256: 89c8b62cc9ceb40c651bbde7ad9210fba81292e9698e05d8365004d65ae79627

Contents?: true

Size: 1.55 KB

Versions: 19

Compression:

Stored size: 1.55 KB

Contents

require "term/ansicolor"
require "gems"
require "semantic"
require "potassium/text_spinner"

module Potassium
  class NewestVersionEnsurer
    include Term::ANSIColor

    def initialize(current_version = Potassium::VERSION)
      self.current_version = Semantic::Version.new(current_version)
      self.text_spinner = Potassium::TextSpinner.new
    end

    def ensure(&success_block)
      spin_text("Checking your Potassium installation") { latest_version }

      self.latest_version = Semantic::Version.new(
        Gems.versions("potassium").first["number"]
      )

      if latest_version <= current_version
        up_to_date
        success_block.call
      else
        please_update
      end
    end

    private

    attr_accessor :latest_version, :current_version, :text_spinner

    def up_to_date
      puts green("\nYour Potassium installation is up to date.")
    end

    def please_update
      puts red("\nYour Potassium installation is not up to date.")
      puts red("Found: #{current_version}")
      puts red("Expected: #{latest_version}\n")
      print white("Please run: ")
      print green("gem update potassium ")
      print white("to upgrade your potassium installation.\n\n")
      print white("If you really need to run this outdated version of potassium anyway, ")
      print white("re-run this command with the ")
      print black("--no-version-check")
      puts white(" flag.")
    end

    def spin_text(message, &block)
      text_spinner.wait_condition = block
      text_spinner.base_message = message
      text_spinner.start
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
potassium-6.0.0 lib/potassium/newest_version_ensurer.rb
potassium-5.2.3 lib/potassium/newest_version_ensurer.rb
potassium-5.2.2 lib/potassium/newest_version_ensurer.rb
potassium-5.2.1 lib/potassium/newest_version_ensurer.rb
potassium-5.2.0 lib/potassium/newest_version_ensurer.rb
potassium-5.1.4 lib/potassium/newest_version_ensurer.rb
potassium-5.1.3 lib/potassium/newest_version_ensurer.rb
potassium-5.1.2 lib/potassium/newest_version_ensurer.rb
potassium-5.1.1 lib/potassium/newest_version_ensurer.rb
potassium-3.0.0 lib/potassium/newest_version_ensurer.rb
potassium-2.3.0 lib/potassium/newest_version_ensurer.rb
potassium-2.2.0 lib/potassium/newest_version_ensurer.rb
potassium-2.1.0 lib/potassium/newest_version_ensurer.rb
potassium-2.0.0 lib/potassium/newest_version_ensurer.rb
potassium-1.3.5 lib/potassium/newest_version_ensurer.rb
potassium-1.3.4 lib/potassium/newest_version_ensurer.rb
potassium-1.3.3 lib/potassium/newest_version_ensurer.rb
potassium-1.3.2 lib/potassium/newest_version_ensurer.rb
potassium-1.3.0 lib/potassium/newest_version_ensurer.rb