Module: RailVerdict::Analyzers::Shared

Defined in:
lib/rail_verdict/analyzers/_shared.rb

Class Method Summary collapse

Class Method Details

.bounded_message(message) ⇒ Object



8
9
10
# File 'lib/rail_verdict/analyzers/_shared.rb', line 8

def bounded_message(message)
  message.to_s.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "?")[0, 4096]
end

.detail_for(run_result) ⇒ Object



12
13
14
15
16
# File 'lib/rail_verdict/analyzers/_shared.rb', line 12

def detail_for(run_result)
  detail = run_result.detail.to_s
  stderr = run_result.stderr.to_s.lines.first.to_s.strip
  bounded_message([detail, stderr].reject(&:empty?).join(": "))
end

.execution_message(run_result) ⇒ Object



18
19
20
21
22
23
# File 'lib/rail_verdict/analyzers/_shared.rb', line 18

def execution_message(run_result)
  message = run_result.stderr.to_s.lines.first.to_s.strip
  message = "#{run_result.detail}" if message.empty?
  message = "execution failed with status #{run_result.exit_code}" if message.empty?
  bounded_message(message)
end

.failure_result(analyzer_id:, invocation:, status:, message:, tool_version: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rail_verdict/analyzers/_shared.rb', line 41

def failure_result(analyzer_id:, invocation:, status:, message:, tool_version: nil)
  status = status.to_s
  AnalyzerResult.new(
    analyzer: analyzer_id,
    tool_version: tool_version,
    invocation: invocation,
    execution_status: status,
    finding_ids: [],
    failure: { "code" => status, "message" => bounded_message(message.to_s) }
  )
end

.invocation_for(command, arguments) ⇒ Object



34
35
36
37
38
39
# File 'lib/rail_verdict/analyzers/_shared.rb', line 34

def invocation_for(command, arguments)
  {
    "executable" => command.fetch(:executable),
    "argv" => command.fetch(:args_prefix).dup.concat(arguments)
  }
end

.parse_semver(output) ⇒ Object



29
30
31
32
# File 'lib/rail_verdict/analyzers/_shared.rb', line 29

def parse_semver(output)
  match = output.to_s.match(/\b(\d+\.\d+\.\d+)\b/)
  match && match[1]
end

.truncated?(run_result) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rail_verdict/analyzers/_shared.rb', line 25

def truncated?(run_result)
  run_result.stdout_truncated || run_result.stderr_truncated
end