Sha256: 6e6db2af440190e02d7e2dc7eb070eca2901239e4acd8ec59eaf17210c022810
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true require "tty-command" module CobraCommander module Executor # # This is a helper module to help jobs return valid errors and success outputs. # # A CobraCommander::Executor::Job is actually any object responding to #call, and returning # valid error or success responses. # # An error is an array containint `:error` and the output (i.e.: [:error, "string output"]). # A success is either an array containint `:success` and the output, or just the output # (i.e.: [:error, "string output"] or just "string output"). # module Job def skip(reason) [:skip, reason] end def error(output) [:error, output] end def success(output) [:success, output] end def run_script(script, path) result = isolate_bundle do TTY::Command.new(pty: true, printer: :null) .run!(script, chdir: path, err: :out) end return error(result.out) if result.failed? success(result.out) end private def isolate_bundle(&block) if Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env(&block) else Bundler.with_clean_env(&block) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cobra_commander-1.0.1 | lib/cobra_commander/executor/job.rb |
cobra_commander-1.0.0 | lib/cobra_commander/executor/job.rb |