Module: Unravel

Defined in:
lib/unravel.rb,
lib/unravel/exec.rb,
lib/unravel/version.rb

Overview

TODO: don’t allow replacing the error

Defined Under Namespace

Classes: Exec, HumanInterventionNeeded, NoKnownRootCause, Registry, SameCauseReoccurringCause, Session

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.Capture(args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/unravel/exec.rb', line 25

def Capture(args)
  Unravel.logger.debug "  -> Running: #{args.inspect}"
  out, error, status = Open3.capture3(*args)
  return out if status.success?
  Unravel.logger.debug "Errors from #{args.inspect}: -----"
  Unravel.logger.debug "#{error}"
  error = out if error.strip.empty?
  raise Exec::Error, error
rescue Errno::ENOENT => e
  raise Exec::Error, e.message
end

.Exec(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/unravel/exec.rb', line 11

def Exec(args)
  Unravel.logger.debug "  -> Running: #{args.inspect}"
  out, error, status = Open3.capture3(*args)
  Unravel.logger.debug "Output from #{args.inspect}: -----"
  Unravel.logger.debug "#{out}"
  return true if status.success?
  Unravel.logger.debug "Errors from #{args.inspect}: -----"
  Unravel.logger.debug "#{error}"
  error = out if error.strip.empty?
  raise Exec::Error, error
rescue Errno::ENOENT => e
  raise Exec::Error, e.message
end

.loggerObject



11
12
13
14
15
16
17
18
# File 'lib/unravel.rb', line 11

def self.logger
  @@logger ||= Logger.new(STDOUT).tap do |logger|
    logger.level = Logger::DEBUG
    logger.formatter = proc do |severity, datetime, progname, msg|
      "#{severity}: #{msg}\n"
    end
  end
end

.run(*args) ⇒ Object



7
8
9
# File 'lib/unravel/exec.rb', line 7

def run(*args)
  Exec(args)
end