Class: SkillBench::Services::OutputPersistenceService Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/services/output_persistence_service.rb

Overview

Deprecated.

Use Cli::RunCommand output handling instead.

Service object for persisting evaluation results to JSON files. Handles file I/O, JSON serialization, and provides standardized error responses for filesystem operations.

Constant Summary collapse

WRITE_ERROR =
'Failed to write output file'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, output_path:) ⇒ OutputPersistenceService

Initializes a new persistence service instance.

Parameters:

  • result (Hash)

    Evaluation result hash containing all evaluation data

  • output_path (String, nil)

    Path to save the JSON report



37
38
39
40
# File 'lib/skill_bench/services/output_persistence_service.rb', line 37

def initialize(result, output_path:)
  @result = result
  @output_path = output_path
end

Class Method Details

.call(result, output_path:) ⇒ Hash

Persists evaluation results to a JSON file with proper formatting.

Examples:

Save to file

result = OutputPersistenceService.call(evaluation_result, output_path: 'output.json')
# => { success: true, response: { message: 'Report saved to output.json' } }

No output path

result = OutputPersistenceService.call(evaluation_result, output_path: nil)
# => { success: true, response: {} }

Parameters:

  • result (Hash)

    Evaluation result hash containing all evaluation data

  • output_path (String, nil)

    Path to save the JSON report. If nil or empty, no action is taken

Returns:

  • (Hash)

    Standardized response hash with format:

    • { success: true, response: { message: String } } on success

    • { success: true, response: {} } when no output path is provided

    • { success: false, response: { error: { message: String } } } on failure



29
30
31
# File 'lib/skill_bench/services/output_persistence_service.rb', line 29

def self.call(result, output_path:)
  new(result, output_path: output_path).call
end

Instance Method Details

#callHash

Persists the evaluation result to the specified output path.

Returns:

  • (Hash)

    Standardized response hash with format:

    • { success: true, response: { message: String } } on success

    • { success: true, response: {} } when no output path is provided

    • { success: false, response: { error: { message: String } } } on failure

Raises:

  • (SystemCallError)

    when file system operations fail (handled internally)



49
50
51
52
53
54
55
56
57
58
# File 'lib/skill_bench/services/output_persistence_service.rb', line 49

def call
  return { success: true, response: {} } if @output_path.to_s.empty?

  ensure_directory_exists
  write_json_file

  { success: true, response: { message: "Report saved to #{@output_path}" } }
rescue SystemCallError, JSON::GeneratorError => e
  { success: false, response: { error: { message: "#{WRITE_ERROR}: #{e.message}" } } }
end