class Loom::Shell::HarnessCommandBuilder

Constants

DEFAULT_RUN_OPTS
SCRIPT

TODO: Resolve a real script path.

Public Class Methods

new(harness_blob) click to toggle source
# File lib/loom/shell/harness_command_builder.rb, line 16
def initialize(harness_blob)
  @harness_blob = harness_blob
  @run_opts = DEFAULT_RUN_OPTS.dup
end

Public Instance Methods

check_cmd() click to toggle source
# File lib/loom/shell/harness_command_builder.rb, line 28
def check_cmd
  build_cmd :check, @harness_blob.checksum, {
              :stdin => @harness_blob.encoded_script
            }
end
run_cmd() click to toggle source
# File lib/loom/shell/harness_command_builder.rb, line 21
def run_cmd
  build_cmd :run, @harness_blob.checksum, *hash_to_opts_array(@run_opts),
            {
              :stdin => @harness_blob.encoded_script
            }
end

Private Instance Methods

build_cmd(cmd, *args, stdin: nil) click to toggle source
# File lib/loom/shell/harness_command_builder.rb, line 41
def build_cmd(cmd, *args, stdin: nil)
  raise HarnessMissingStdin unless stdin

  heredoc = "<<'HARNESS_EOS'\n#{stdin}\nHARNESS_EOS"
  cmd = "--" + cmd.to_s
  "%s %s 2>/dev/null - %s %s" % [SCRIPT, cmd, args.join(" "), heredoc]
end
hash_to_opts_array(hash) click to toggle source
# File lib/loom/shell/harness_command_builder.rb, line 35
def hash_to_opts_array(hash)
  hash.to_a.map do |tuple|
    "--%s %s" % [tuple.first, tuple.last]
  end
end