Class: Foruiman::Diagnostics

Inherits:
Object
  • Object
show all
Defined in:
lib/foruiman/diagnostics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interactive:, stderr: $stderr) ⇒ Diagnostics

Returns a new instance of Diagnostics.



6
7
8
9
10
# File 'lib/foruiman/diagnostics.rb', line 6

def initialize(interactive:, stderr: $stderr)
  @interactive = interactive
  @temporary = nil
  @output = stderr
end

Instance Attribute Details

#path ⇒ Object (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/foruiman/diagnostics.rb', line 4

def path
  @path
end

Instance Method Details

#close ⇒ Object



24
25
26
# File 'lib/foruiman/diagnostics.rb', line 24

def close
  @temporary&.close
end

#error(exception) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/foruiman/diagnostics.rb', line 12

def error(exception)
  if @interactive && !@temporary
    require "tempfile"
    @temporary = Tempfile.create(["foruiman-", ".log"])
    @temporary.chmod(0o600)
    @output = @temporary
    @path = @temporary.path
  end
  @output.puts(exception.full_message(highlight: false))
  @output.flush
end