Class: Lrun::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lrun/runner.rb

Overview

Lrun provides essential methods to run program with different options using lrun binary.

Runner makes it easier to run many programs with same options.

Example

runner = Lrun::Runner.new(:max_cpu_time=>1, :tmpfs=>[["/tmp", 2**20]], :chdir=>"/tmp")
# or:
runner = Lrun::Runner.new.where(:max_cpu_time=>1, :tmpfs=>[["/tmp", 2**20]], :chdir=>"/tmp")
# or:
runner = Lrun::Runner.new.max_cpu_time(1).tmpfs('/tmp' => 2**20).chdir('/tmp')

runner.options
# => {:max_cpu_time=>1, :tmpfs=>[["/tmp", 1048576]], :chdir=>"/tmp"} 
runner.max_cpu_time(nil).options
# => {:tmpfs=>[["/tmp", 1048576]], :chdir=>"/tmp"} 

runner.run('pwd').stdout
# => "/tmp\n"
runner.cmd("touch `seq 1 4`").run('ls').stdout
# => "1\n2\n3\n4\n"
runner.cmd("echo 'puts ENV[?A]' > a.rb").env('A' => 'Hello').run('ruby a.rb').stdout
# => "Hello\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner


56
57
58
# File 'lib/lrun/runner.rb', line 56

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsHash


53
54
55
# File 'lib/lrun/runner.rb', line 53

def options
  @options
end

Instance Method Details

#run(commands) ⇒ Object

Run commands using current #options.

See Also:


71
72
73
# File 'lib/lrun/runner.rb', line 71

def run(commands)
  Lrun.run commands, @options
end

#where(options) ⇒ Lrun::Runner

Create a new runner with new options

Raises:

  • (TypeError)

79
80
81
82
# File 'lib/lrun/runner.rb', line 79

def where(options)
  raise TypeError, 'expect options to be a Hash' unless options.is_a? Hash
  Lrun::Runner.new(Lrun.merge_options(@options, options))
end