Sha256: 1a1623f7d92ab48b85233b63ef864ffa00e6e39dcb3447a0aca6763292d505cb

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

require 'gems'
require 'semantic'
require 'potassium/text_spinner'

class VersionError < StandardError
end

module Potassium
  class NewestVersionEnsurer
    def initialize
      self.installed_version = Semantic::Version.new(Potassium::VERSION)
      self.text_spinner = Potassium::TextSpinner.new
    end

    def ensure!
      spin_text('Checking your Potassium installation') { published_version }

      self.published_version = Semantic::Version.new(Gems.versions('potassium').first['number'])
      raise VersionError.new(update_message) if published_version > installed_version
    end

    private

    attr_accessor :published_version, :installed_version, :text_spinner

    def update_message
      <<~HERE
        Your potassium installation is not up to date.
        The last available version is #{published_version} while the running version is #{installed_version}.
        If you really need to run this outdated version of potassium, re-run this command with the `--no-version-check` flag.
      HERE
    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

10 entries across 10 versions & 1 rubygems

Version Path
potassium-7.2.0 lib/potassium/newest_version_ensurer.rb
potassium-7.1.0 lib/potassium/newest_version_ensurer.rb
potassium-7.0.0 lib/potassium/newest_version_ensurer.rb
potassium-6.7.0 lib/potassium/newest_version_ensurer.rb
potassium-6.6.0 lib/potassium/newest_version_ensurer.rb
potassium-6.5.0 lib/potassium/newest_version_ensurer.rb
potassium-6.4.0 lib/potassium/newest_version_ensurer.rb
potassium-6.3.0 lib/potassium/newest_version_ensurer.rb
potassium-6.2.0 lib/potassium/newest_version_ensurer.rb
potassium-6.1.0 lib/potassium/newest_version_ensurer.rb