Module: Bricolage::CommandUtils

Included in:
PSQLDataSource
Defined in:
lib/bricolage/commandutils.rb

Instance Method Summary collapse

Instance Method Details

#command(*args, env: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/bricolage/commandutils.rb', line 7

def command(*args, env: nil)
  logger.info "command: #{args.join(' ')}"
  sargs = args.map {|a| a.to_s }
  sargs.unshift env if env
  system(*sargs)
  st = $?
  logger.info "status: #{st.exitstatus || 'nil'} (#{st})"
  st
end

#make_tmpfile(content, tmpdir: Dir.tmpdir) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bricolage/commandutils.rb', line 17

def make_tmpfile(content, tmpdir: Dir.tmpdir)
  path = new_tmpfile_path(tmpdir)
  File.open(path, 'w') {|f|
    f.write content
  }
  yield path
ensure
  FileUtils.rm_f path
end

#new_tmpfile_path(tmpdir = Dir.tmpdir) ⇒ Object



27
28
29
# File 'lib/bricolage/commandutils.rb', line 27

def new_tmpfile_path(tmpdir = Dir.tmpdir)
  "#{tmpdir}/#{Time.now.to_i}_#{$$}_#{'%x' % Thread.current.object_id}_#{rand(2**16)}"
end