Class: SkillBench::Config::JsonLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/config/json_loader.rb

Overview

Loads and normalizes evaluator JSON configuration files.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ JsonLoader

Initializes the loader.

Parameters:

  • path (Pathname)

    path to the JSON configuration file



21
22
23
# File 'lib/skill_bench/config/json_loader.rb', line 21

def initialize(path)
  @path = path
end

Class Method Details

.call(path) ⇒ Hash

Loads a JSON config file into a normalized hash.

Parameters:

  • path (Pathname)

    path to the JSON configuration file

Returns:

  • (Hash)

    result envelope with normalized configuration values



13
14
15
# File 'lib/skill_bench/config/json_loader.rb', line 13

def self.call(path)
  new(path).call
end

Instance Method Details

#callHash

Loads a JSON config file into a normalized hash.

Returns:

  • (Hash)

    result envelope with normalized configuration values



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/skill_bench/config/json_loader.rb', line 28

def call
  data = JSON.parse(File.read(@path), symbolize_names: true)
  return warn_invalid_config unless data.is_a?(Hash)

  success(data.slice(:current_llm_provider, :max_execution_time, :allowed_commands)
              .compact
              .merge(providers: normalized_providers(data[:providers])))
rescue JSON::ParserError => e
  log_parse_error(e)
  failure('Failed to parse config file')
rescue StandardError => e
  SkillBench::ErrorLogger.log_error(e, 'JsonLoader Error')
  failure(e.message)
end