Class: Rodiff::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/rodiff/executable.rb

Defined Under Namespace

Classes: ExecutableNotFound, InstallDirectoryNotFound, UnsupportedPlatform

Constant Summary collapse

DEFAULT_DIR =
File.expand_path(File.join(__dir__, "..", "..", "exe"))
LOCAL_INSTALL_DIR_ENV =
"ODIFF_INSTALL_DIR"

Class Method Summary collapse

Class Method Details

.platformObject



56
57
58
# File 'lib/rodiff/executable.rb', line 56

def platform
  %i[cpu os].map { |m| Gem::Platform.local.public_send(m) }.join("-")
end

.resolve(exe_path: DEFAULT_DIR) ⇒ Object

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rodiff/executable.rb', line 66

def resolve(exe_path: DEFAULT_DIR)
  if (odiff_install_dir = ENV.fetch(LOCAL_INSTALL_DIR_ENV, nil))
    exe_path = odiff_install_dir
    exe_file = expand_local_install_dir(odiff_install_dir)
  elsif supported_platform?
    exe_file = expand_bundled_dir(exe_path)
  else
    raise UnsupportedPlatform, platform
  end

  raise ExecutableNotFound.new(platform, exe_path) if exe_file.nil? || !File.exist?(exe_file)

  exe_file
end

.supported_platform?(platform = nil) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/rodiff/executable.rb', line 60

def supported_platform?(platform = nil)
  return Gem::Platform.match_gem?(Gem::Platform.new(platform), "rodiff") unless platform.nil?

  Rodiff::Odiff::PLATFORMS.keys.any? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), "rodiff") }
end