Class: GeneSystem::Platform
- Inherits:
-
Object
- Object
- GeneSystem::Platform
- Defined in:
- lib/gene_system/platform.rb
Overview
Platform is a class to handle command execution on host system
Instance Method Summary collapse
-
#execute_command(cmd, vars = {}) ⇒ Integer
Executes a command on a host system and returns command exit code.
-
#execute_commands(cmds = [], vars = {}) ⇒ Object
Takes an array of commands for the host and executes each one.
-
#initialize ⇒ Platform
constructor
Platform constructor.
-
#posix? ⇒ Boolean
Posix platform check.
Constructor Details
#initialize ⇒ Platform
Platform constructor. Raises unsupported platform RuntimeError when the host system is not a posix system.
12 13 14 |
# File 'lib/gene_system/platform.rb', line 12 def initialize raise 'unsupported platform' unless posix? end |
Instance Method Details
#execute_command(cmd, vars = {}) ⇒ Integer
Executes a command on a host system and returns command exit code
37 38 39 40 41 42 43 44 |
# File 'lib/gene_system/platform.rb', line 37 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 = {}) ⇒ Object
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
24 25 26 27 28 29 |
# File 'lib/gene_system/platform.rb', line 24 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? ⇒ Boolean
Posix platform check. Returns true if host is a posix system i.e. Mac/Linux etc.
52 53 54 |
# File 'lib/gene_system/platform.rb', line 52 def posix? OS.posix? end |