Module: Tebako::BuildHelpers
- Defined in:
- lib/tebako/build_helpers.rb
Overview
Ruby build helpers
Class Method Summary collapse
- .run_with_capture(args) ⇒ Object
- .run_with_capture_v(args) ⇒ Object
-
.with_env(hash) ⇒ Object
Sets up temporary environment variables and yields to the block.
Class Method Details
.run_with_capture(args) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/tebako/build_helpers.rb', line 35 def run_with_capture(args) args = args.compact puts " ... @ #{args.join(" ")}" out, st = Open3.capture2e(*args) raise Tebako::Error, "Failed to run #{args.join(" ")} (#{st}):\n #{out}" if st.signaled? || !st.exitstatus.zero? out end |
.run_with_capture_v(args) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/tebako/build_helpers.rb', line 44 def run_with_capture_v(args) if @verbose args_v = args.dup args_v.push("--verbose") puts run_with_capture(args_v) else run_with_capture(args) end end |
.with_env(hash) ⇒ Object
Sets up temporary environment variables and yields to the block. When the block exits, the environment variables are set back to their original values.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tebako/build_helpers.rb', line 57 def with_env(hash) old = {} hash.each do |k, v| old[k] = ENV.fetch(k, nil) ENV[k] = v end begin yield ensure hash.each_key { |k| ENV[k] = old[k] } end end |