Class: DanarchyDeploy::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/helpers.rb

Class Method Summary collapse

Class Method Details

.decode_base64(data) ⇒ Object



27
28
29
# File 'lib/danarchy_deploy/helpers.rb', line 27

def self.decode_base64(data)
  Base64.decode64(data)
end

.encode_base64(data) ⇒ Object



31
32
33
# File 'lib/danarchy_deploy/helpers.rb', line 31

def self.encode_base64(data)
  Base64.encode64(data)
end

.run_command(command, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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