module Evrone::CI::Common::Helper::Shell

Private Instance Methods

bash(*args, &block) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 62
def bash(*args, &block)
  raise ArgumentError, 'block required' unless block_given?

  options = args.last.is_a?(Hash) ? args.pop : {}
  command = args.first

  cmd = "/usr/bin/env -i HOME=${HOME} bash"

  if file = options.delete(:file)
    cmd << " #{file}"
  else
    cmd << " -c " << Shellwords.escape(command)
  end

  runner = options.delete(:ssh) || self
  runner.send(:spawn, cmd, options, &block)
end
expand_path(path) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 58
def expand_path(path)
  File.expand_path path.to_s
end
mkdir(name) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 23
def mkdir(name)
  FileUtils.mkdir_p name.to_s
end
path(name) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 19
def path(name)
  Pathname.new(name)
end
read_file(name) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 52
def read_file(name)
  if File.readable?(name)
    File.read name
  end
end
recreate(name) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 31
def recreate(name)
  rm name
  mkdir name
end
rm(name) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 27
def rm(name)
  FileUtils.rm_rf name.to_s
end
write_file(name, content, perm = 0644) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 36
def write_file(name, content, perm = 0644)
  File.open(name, 'w', perm) do |io|
    io.write content
  end
end
write_tmp_file(name, content, perm = 0600) click to toggle source
# File lib/evrone/ci/common/helper/shell.rb, line 42
def write_tmp_file(name, content, perm = 0600)
  tmp = ::Tempfile.new name
  tmp.write content
  tmp.rewind
  tmp.flush
  tmp.close
  FileUtils.chmod perm, tmp.path
  tmp
end