Module: Dply::Helper
- Included in:
- Archive, Build, BuildConfig, Bundle, Cli::Depcheck, Cli::InstallPkgs, Config, ConfigDownloader, Curl, Deplist, Git, Jenkins, Linker, Lock, Pkgs, Release, Rpm, Setup, Strategy::Archive, Strategy::Git, Tasks, Yum, Dplyr::Stage, Dplyr::StagesConfig, Dplyr::TasksConfig
- Defined in:
- lib/dply/helper.rb
Instance Method Summary collapse
- #cmd(command, display: true, error_msg: nil, return_output: false, env: {}, shell: false) ⇒ Object
- #error(msg) ⇒ Object
- #git ⇒ Object
- #logger ⇒ Object
- #stringify_values!(hash) ⇒ Object
- #symlink(src, dst) ⇒ Object
Instance Method Details
#cmd(command, display: true, error_msg: nil, return_output: false, env: {}, shell: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dply/helper.rb', line 9 def cmd(command, display: true, error_msg: nil, return_output: false, env:{}, shell: false) stringify_values!(env) if display logger.bullet command else logger.debug command end command_arr = command.split run_command = shell ? command : command_arr output = if return_output IO.popen(env, run_command) { |f| f.read } else system(env, *run_command, 2 => 1) end return_value = $?.exitstatus error_msg ||= "non zero exit for \"#{command}\"" error error_msg if return_value != 0 return output end |
#error(msg) ⇒ Object
58 59 60 |
# File 'lib/dply/helper.rb', line 58 def error(msg) raise ::Dply::Error, msg end |
#git ⇒ Object
54 55 56 |
# File 'lib/dply/helper.rb', line 54 def git Git end |
#logger ⇒ Object
50 51 52 |
# File 'lib/dply/helper.rb', line 50 def logger Logger.logger end |
#stringify_values!(hash) ⇒ Object
44 45 46 47 48 |
# File 'lib/dply/helper.rb', line 44 def stringify_values!(hash) hash.each do |k,v| hash[k] = v.to_s end end |
#symlink(src, dst) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dply/helper.rb', line 30 def symlink(src, dst) if File.symlink? dst Dir.mktmpdir("sym-", "./") do |d| dst_tmp = "#{d}/#{File.basename dst}" FileUtils.ln_s src, dst_tmp cmd "mv #{dst_tmp} #{File.dirname dst}", display: false end elsif File.exist? dst error "cannot create symlink #{dst} => #{src}" else FileUtils.ln_s src, dst end end |