class GeneSystem::Platform

Platform is a class to handle command execution on host system

Public Class Methods

new() click to toggle source

Platform constructor. Raises unsupported platform RuntimeError when the host system is not a posix system.

# File lib/gene_system/platform.rb, line 11
def initialize
  raise 'unsupported platform' unless posix?
end

Public Instance Methods

execute_command(cmd, vars = {}) click to toggle source

Executes a command on a host system and returns command exit code

@param [String] cmd

@return [Integer]

# File lib/gene_system/platform.rb, line 36
def execute_command(cmd, vars = {})
  hbs = Handlebars::Handlebars.new

  pid = Process.spawn(hbs.compile(cmd).call(vars))
  _, status = Process.waitpid2(pid)

  status.exitstatus
end
execute_commands(cmds = [], vars = {}) click to toggle source

Takes an array of commands for the host and executes each one

If command returns non zero status code, then a command failed RuntimeError will be raised

@param cmds

# File lib/gene_system/platform.rb, line 23
def execute_commands(cmds = [], vars = {})
  cmds.each do |cmd|
    status = execute_command(cmd, vars)
    raise "command `#{cmd}` failed - returned #{status}" unless status.zero?
  end
end
posix?() click to toggle source

Posix platform check. Returns true if host is a posix system i.e. Mac/Linux etc.

@return [Boolean]

# File lib/gene_system/platform.rb, line 51
def posix?
  OS.posix?
end