class DanarchyDeploy::Helpers

Public Class Methods

decode_base64(data) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 27
def self.decode_base64(data)
  Base64.decode64(data)
end
encode_base64(data) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 31
def self.encode_base64(data)
  Base64.encode64(data)
end
run_command(command, options) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 6
def self.run_command(command, options)
  pid, stdout, stderr = nil
  printf("%14s %0s\n", 'Running:', "#{command}")

  if options[:pretend] && !options[:dev_gem]
    pretend_run(command)
  else
    Open3.popen3(command) do |i, o, e, t|
      pid    = t.pid
      (out, err) = o.read, e.read
      stdout = !out.empty? ? out : nil
      stderr = !err.empty? ? err : nil
    end

    puts "------\nErrored at: #{caller_locations.first.label} Line: #{caller_locations.first.lineno}\nSTDERR: ", stderr, '------' if stderr
    puts "------\nSTDOUT: ", stdout, '------' if stdout && options[:ssh_verbose]
  end
  
  { pid: pid, stdout: stdout, stderr: stderr }
end

Private Class Methods

hash_except(hash, regex) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 40
def self.hash_except(hash, regex)
  hash.dup.delete_if { |k,v| k.to_s =~ /#{regex}/ }
end
hash_symbols_to_strings(hash) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 44
def self.hash_symbols_to_strings(hash)
  new_hash = Hash.new
  hash.each do |key, val|
    if val.class == Hash
      new_hash[key.to_s] = Hash.new
      val.each do |k, v|
        new_hash[key.to_s][k.to_s] = v
      end
    else
      new_hash[key.to_s] = val
    end
  end

  new_hash
end
pretend_run(command) click to toggle source
# File lib/danarchy_deploy/helpers.rb, line 36
def self.pretend_run(command)
  puts "\tFake run: #{command}"
end