Module: Opener::BuildTools::Requirements

Defined in:
lib/opener/build-tools/requirements.rb

Overview

Module that provides various helper methods for ensuring certain executables exist, version requirements are met and so on.

Class Method Summary collapse

Class Method Details

.require_executable(name) ⇒ Object

Checks if a given executable can be found in $PATH and aborts if this isn’t the case.

Examples:

require_executable('python')

Parameters:

  • name (String)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/opener/build-tools/requirements.rb', line 19

def require_executable(name)
  print "Checking for #{name}... "

  exists = false

  ENV['PATH'].split(File::PATH_SEPARATOR).each do |directory|
    path = File.join(directory, name)

    if File.executable?(path)
      exists = true
      break
    end
  end

  if exists
    puts 'yes'
  else
    abort 'no'
  end
end

.require_version(name, current, required) ⇒ Object

Checks if the version specified in ‘current` is greater than or equal to the version specified in `requirement`.

Examples:

Ensures that Python’s version is >= 2.7.0

require_version('python', '2.7.5', '2.7.0')

Parameters:

  • name (String)

    The name of the executable.

  • current (String)

    The current version.

  • required (String)

    The minimum required version.



51
52
53
54
55
56
57
58
59
# File 'lib/opener/build-tools/requirements.rb', line 51

def require_version(name, current, required)
  print "Checking for #{name} >= #{required}... "

  if version_greater_than(current, required)
    puts 'yes'
  else
    abort 'no'
  end
end

.version_greater_than(left, right) ⇒ TrueClass|FalseClass

Checks if the version string to the left is greater or equal to the version string on the right.

Parameters:

  • left (String)
  • right (String)

Returns:

  • (TrueClass|FalseClass)


69
70
71
# File 'lib/opener/build-tools/requirements.rb', line 69

def version_greater_than(left, right)
  return Gem::Version.new(left) >= Gem::Version.new(right)
end