Module: Kompo::KompoVfsVersionCheck

Defined in:
lib/kompo/tasks/kompo_vfs_version_check.rb

Overview

Verifies that the installed kompo-vfs version meets minimum requirements. Checks the KOMPO_VFS_VERSION file in the library directory.

Defined Under Namespace

Classes: IncompatibleVersionError

Constant Summary collapse

VERSION_FILE =
"KOMPO_VFS_VERSION"

Class Method Summary collapse

Class Method Details

.build_error_message(actual_version, required_version) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kompo/tasks/kompo_vfs_version_check.rb', line 34

def self.build_error_message(actual_version, required_version)
  <<~MSG.chomp
    kompo-vfs version #{actual_version} is too old.
    Required: >= #{required_version}

    Please upgrade:
      Homebrew: brew update && brew upgrade kompo-vfs
        (If upgrade fails, try: brew tap --force-auto-update ahogappa/kompo)
      Source: cd ~/.kompo/kompo-vfs && git pull && cargo build --release
  MSG
end

.build_missing_file_message(version_file) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kompo/tasks/kompo_vfs_version_check.rb', line 46

def self.build_missing_file_message(version_file)
  <<~MSG.chomp
    kompo-vfs version file not found at: #{version_file}
    Your kompo-vfs installation may be outdated (< 0.5.0).

    Please upgrade:
      Homebrew: brew update && brew upgrade kompo-vfs
        (If upgrade fails, try: brew tap --force-auto-update ahogappa/kompo)
      Source: cd ~/.kompo/kompo-vfs && git pull && cargo build --release
  MSG
end

.get_version(lib_path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/kompo/tasks/kompo_vfs_version_check.rb', line 22

def self.get_version(lib_path)
  version_file = File.join(lib_path, VERSION_FILE)

  raise IncompatibleVersionError, build_missing_file_message(version_file) unless File.exist?(version_file)

  File.read(version_file).strip
end

.verify!(lib_path) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/kompo/tasks/kompo_vfs_version_check.rb', line 13

def self.verify!(lib_path)
  actual_version = get_version(lib_path)
  required_version = Kompo::KOMPO_VFS_MIN_VERSION

  return if version_satisfies?(actual_version, required_version)

  raise IncompatibleVersionError, build_error_message(actual_version, required_version)
end

.version_satisfies?(actual, required) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/kompo/tasks/kompo_vfs_version_check.rb', line 30

def self.version_satisfies?(actual, required)
  Gem::Version.new(actual) >= Gem::Version.new(required)
end