Module: LetsencryptHeroku::Tools

Instance Method Summary collapse

Instance Method Details



3
4
5
# File 'lib/letsencrypt_heroku/tools.rb', line 3

def banner(msg, values = nil)
  puts "\n #{Rainbow(msg).blue} #{values.to_s}\n\n"
end

#error(reason = nil) ⇒ Object



22
23
24
25
26
# File 'lib/letsencrypt_heroku/tools.rb', line 22

def error(reason = nil)
  log reason, level: :error
  @_spinner && @_spinner.error("(#{reason.strip})")
  raise LetsencryptHeroku::TaskError, reason
end

#execute(command, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/letsencrypt_heroku/tools.rb', line 28

def execute(command, &block)
  log command
  Open3.popen3("unset RUBYOPT; #{command}") do |stdin, stdout, stderr, wait_thr|
    if block
      block.call(stdin, stdout, stderr, wait_thr)
    else
      out, err = stdout.read, stderr.read
      log out
      log err
      wait_thr.value.success? or error(err.force_encoding('utf-8').sub('', 'heroku: '))
    end
  end
end

#log(message, level: :info) ⇒ Object



17
18
19
20
# File 'lib/letsencrypt_heroku/tools.rb', line 17

def log(message, level: :info)
  message.to_s.empty? and return
  level == :info ? logger.info(message) : logger.error(message)
end

#output(name, &block) ⇒ Object



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

def output(name, &block)
  log name
  @_spinner = build_spinner(name)
  @_spinner.auto_spin
  block.call
  @_spinner.success
rescue LetsencryptHeroku::TaskError
  exit false
end