Class: SkillBench::Models::Config
- Inherits:
-
Object
- Object
- SkillBench::Models::Config
- Defined in:
- lib/skill_bench/models/config.rb
Overview
Represents the skill-bench configuration loaded from skill-bench.json
Class Method Summary collapse
-
.load(path = 'skill-bench.json') ⇒ SkillBench::Models::Config
Load configuration from a JSON file.
-
.loaded(path = 'skill-bench.json') ⇒ SkillBench::Models::Config
Returns the configuration for a path, memoizing the parse per run.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Config
constructor
A new instance of Config.
-
#max_execution_time ⇒ Integer
Returns max execution time.
-
#mock? ⇒ Boolean
Indicates whether the config explicitly selects the built-in mock provider, as opposed to having no provider configured at all.
-
#provider_config ⇒ Hash
Returns the provider configuration.
-
#provider_name ⇒ String?
Returns the configured provider name.
-
#to_provider ⇒ SkillBench::Models::Provider
Builds a Provider model from the current configuration.
Constructor Details
#initialize(data = {}) ⇒ Config
Returns a new instance of Config.
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
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.
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.(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_time ⇒ Integer
Returns max execution time
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.
67 68 69 |
# File 'lib/skill_bench/models/config.rb', line 67 def mock? provider_name == 'mock' end |
#provider_config ⇒ Hash
Returns the provider configuration
59 60 61 |
# File 'lib/skill_bench/models/config.rb', line 59 def provider_config @data[:config] || {} end |
#provider_name ⇒ String?
Returns the configured provider name
53 54 55 |
# File 'lib/skill_bench/models/config.rb', line 53 def provider_name @data[:provider] end |
#to_provider ⇒ SkillBench::Models::Provider
Builds a Provider model from the current configuration. Returns a mock provider if provider name is 'mock'.
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 |