Class: Toy::Core::Config
- Inherits:
-
Object
- Object
- Toy::Core::Config
- Defined in:
- lib/toy/core/config.rb
Constant Summary collapse
- DEFAULTS =
{ # Template for runs/<run_id>/ dir names. Brace-placeholder tokens: # {arch} {date}(YYYYMMDD) {time}(HHMMSS) {seq}(zero-padded daily) # Slice 1 stores/echoes only; consumed at train time (P4). "run_id_template" => "{arch}-{date}-{seq}", # Relative dir the registry/discovery walks for user algos (L1-L4). # Slice 1 stores only; discovery is later. "algos_path" => "algos" }.freeze
- KNOWN_KEYS =
DEFAULTS.keys.freeze
Instance Attribute Summary collapse
-
#algos_path ⇒ Object
readonly
Returns the value of attribute algos_path.
-
#run_id_template ⇒ Object
readonly
Returns the value of attribute run_id_template.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Class Method Summary collapse
-
.load(dir = Dir.pwd, warn_io: $stderr) ⇒ Object
Load from a toy.yml at ‘dir` (default: cwd).
Instance Method Summary collapse
-
#initialize(values = {}) ⇒ Config
constructor
A new instance of Config.
- #to_h ⇒ Object
Constructor Details
Instance Attribute Details
#algos_path ⇒ Object (readonly)
Returns the value of attribute algos_path.
28 29 30 |
# File 'lib/toy/core/config.rb', line 28 def algos_path @algos_path end |
#run_id_template ⇒ Object (readonly)
Returns the value of attribute run_id_template.
28 29 30 |
# File 'lib/toy/core/config.rb', line 28 def run_id_template @run_id_template end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
28 29 30 |
# File 'lib/toy/core/config.rb', line 28 def source_path @source_path end |
Class Method Details
.load(dir = Dir.pwd, warn_io: $stderr) ⇒ Object
Load from a toy.yml at ‘dir` (default: cwd). Missing file → all defaults. Empty file → all defaults. Unknown keys → warn.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/toy/core/config.rb', line 38 def self.load(dir = Dir.pwd, warn_io: $stderr) path = File.join(dir, "toy.yml") unless File.file?(path) c = new c.instance_variable_set(:@source_path, nil) return c end raw = YAML.safe_load(File.read(path)) || {} unless raw.is_a?(Hash) warn_io.puts "toy: warning: toy.yml is not a mapping; ignoring its contents" raw = {} end raw.each_key do |k| next if KNOWN_KEYS.include?(k) warn_io.puts "toy: warning: unknown toy.yml key #{k.inspect} (ignored)" end c = new(raw.select { |k, _| KNOWN_KEYS.include?(k) }) c.instance_variable_set(:@source_path, path) c end |
Instance Method Details
#to_h ⇒ Object
59 60 61 |
# File 'lib/toy/core/config.rb', line 59 def to_h { "run_id_template" => @run_id_template, "algos_path" => @algos_path } end |