Class: Aias::ScheduleConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/aias/schedule_config.rb

Overview

Manages ~/.config/aia/schedule/aia.yml — the AIA config file used by all scheduled cron jobs. Provides targeted updates without clobbering user settings already in the file.

Instance Method Summary collapse

Constructor Details

#initialize(path: Paths::SCHEDULE_CFG) ⇒ ScheduleConfig



10
11
12
# File 'lib/aias/schedule_config.rb', line 10

def initialize(path: Paths::SCHEDULE_CFG)
  @path = path
end

Instance Method Details

#set_prompts_dir(dir) ⇒ Object

Sets prompts.dir in the config file to dir if it is not already that value. Returns true when the file was updated, false when already correct or file absent. Raises Aias::Error on YAML parse failure or write error.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aias/schedule_config.rb', line 17

def set_prompts_dir(dir)
  return false unless File.exist?(@path)

  config = YAML.safe_load_file(@path) || {}
  return false if config.dig("prompts", "dir") == dir

  config["prompts"]        ||= {}
  config["prompts"]["dir"]   = dir
  File.write(@path, config.to_yaml)
  true
rescue Psych::Exception => e
  raise Aias::Error, "could not update prompts.dir in #{@path}: #{e.message}"
end