Class: SkillBench::Models::Config

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

Overview

Represents the skill-bench configuration loaded from skill-bench.json

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.

Parameters:

  • data (Hash) (defaults to: {})

    Raw configuration data

Raises:

  • (ArgumentError)

    if data is not a Hash



12
13
14
15
16
# File 'lib/skill_bench/models/config.rb', line 12

def initialize(data = {})
  raise ArgumentError, 'Config-data must be a Hash' unless data.is_a?(Hash)

  @data = data
end

Class Method Details

.load(path = 'skill-bench.json') ⇒ SkillBench::Models::Config

Load configuration from a JSON file

Parameters:

  • path (String) (defaults to: 'skill-bench.json')

    Path to config file (default: skill-bench.json)

Returns:

Raises:

  • (Errno::ENOENT)

    if config file not found



22
23
24
25
# File 'lib/skill_bench/models/config.rb', line 22

def self.load(path = 'skill-bench.json')
  raw_data = JSON.parse(File.read(path), symbolize_names: true)
  new(raw_data)
end

.loaded(path = 'skill-bench.json') ⇒ SkillBench::Models::Config

Returns the configuration for a path, memoizing the parse per run.

Hot paths such as Services::ProviderResolver resolve the provider on every run, yet skill-bench.json is stable within a single run. The parse is cached per absolute path and invalidated when the file's mtime changes, so the file is parsed at most once per run while a rewritten file (for example between tests) is still re-read. Reset by setting the @loaded ivar to nil.

Parameters:

  • path (String) (defaults to: 'skill-bench.json')

    Path to config file (default: skill-bench.json)

Returns:

Raises:

  • (Errno::ENOENT)

    if config file not found



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/skill_bench/models/config.rb', line 39

def self.loaded(path = 'skill-bench.json')
  key = File.expand_path(path)
  mtime = File.mtime(key)
  cache = (@loaded ||= {})
  entry = cache[key]
  return entry[:config] if entry && entry[:mtime] == mtime

  config = load(path)
  cache[key] = { mtime: mtime, config: config }
  config
end

Instance Method Details

#max_execution_timeInteger

Returns max execution time

Returns:

  • (Integer)

    Max execution time in seconds



73
74
75
# File 'lib/skill_bench/models/config.rb', line 73

def max_execution_time
  @data[:max_execution_time] || 30
end

#mock?Boolean

Indicates whether the config explicitly selects the built-in mock provider, as opposed to having no provider configured at all.

Returns:

  • (Boolean)

    true when the configured provider is 'mock'



67
68
69
# File 'lib/skill_bench/models/config.rb', line 67

def mock?
  provider_name == 'mock'
end

#provider_configHash

Returns the provider configuration

Returns:

  • (Hash)

    Provider configuration



59
60
61
# File 'lib/skill_bench/models/config.rb', line 59

def provider_config
  @data[:config] || {}
end

#provider_nameString?

Returns the configured provider name

Returns:

  • (String, nil)

    Provider name



53
54
55
# File 'lib/skill_bench/models/config.rb', line 53

def provider_name
  @data[:provider]
end

#to_providerSkillBench::Models::Provider

Builds a Provider model from the current configuration. Returns a mock provider if provider name is 'mock'.

Returns:



81
82
83
84
85
86
87
88
89
90
# File 'lib/skill_bench/models/config.rb', line 81

def to_provider
  return nil if provider_name.nil? || provider_name == 'mock'

  Provider.new(
    name: provider_name,
    runtime: provider_name,
    llm: provider_name,
    config: provider_config
  )
end