Module: RailVerdict::Analyzers::Shared
- Defined in:
- lib/rail_verdict/analyzers/_shared.rb
Class Method Summary collapse
- .bounded_message(message) ⇒ Object
- .detail_for(run_result) ⇒ Object
- .execution_message(run_result) ⇒ Object
- .failure_result(analyzer_id:, invocation:, status:, message:, tool_version: nil) ⇒ Object
- .invocation_for(command, arguments) ⇒ Object
- .parse_semver(output) ⇒ Object
- .truncated?(run_result) ⇒ Boolean
Class Method Details
.bounded_message(message) ⇒ Object
8 9 10 |
# File 'lib/rail_verdict/analyzers/_shared.rb', line 8 def () .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 ([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 (run_result) = run_result.stderr.to_s.lines.first.to_s.strip = "#{run_result.detail}" if .empty? = "execution failed with status #{run_result.exit_code}" if .empty? () 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" => (.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
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 |