Module: LetsencryptHeroku::Tools
- Included in:
- ConfigBuilder, Process::AuthorizeDomains, Process::PrepareConfig, Process::SetupClient, Process::UpdateCertificates
- Defined in:
- lib/letsencrypt_heroku/tools.rb
Instance Method Summary collapse
- #banner(msg, values = nil) ⇒ Object
- #error(reason = nil) ⇒ Object
- #execute(command, &block) ⇒ Object
- #log(message, level: :info) ⇒ Object
- #output(name, &block) ⇒ Object
Instance Method Details
#banner(msg, values = nil) ⇒ Object
3 4 5 |
# File 'lib/letsencrypt_heroku/tools.rb', line 3 def (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(, level: :info) .to_s.empty? and return level == :info ? logger.info() : logger.error() 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 |