Class: Ace::Support::Models::Atoms::ProviderConfigWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/models/atoms/provider_config_writer.rb

Overview

Writes provider configuration files, preserving structure Updates only the models: section while keeping other fields intact

Class Method Summary collapse

Class Method Details

.backup(path) ⇒ String

Create a backup of a config file

Parameters:

  • path (String)

    Path to config file

Returns:

  • (String)

    Path to backup file



41
42
43
44
45
46
47
48
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 41

def backup(path)
  return nil unless File.exist?(path)

  timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
  backup_path = "#{path}.backup.#{timestamp}"
  FileUtils.cp(path, backup_path)
  backup_path
end

.update_last_synced(path, date = Date.today) ⇒ Boolean

Update the last_synced field in a provider config file

Parameters:

  • path (String)

    Path to config file

  • date (Date) (defaults to: Date.today)

    Date to set (defaults to today)

Returns:

  • (Boolean)

    true on success

Raises:



55
56
57
58
59
60
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 55

def update_last_synced(path, date = Date.today)
  config = read_config(path)
  config["last_synced"] = date
  write(path, config)
  true
end

.update_models(path, models) ⇒ Boolean

Update the models list in a provider config file

Parameters:

  • path (String)

    Path to config file

  • models (Array<String>)

    New list of model IDs

Returns:

  • (Boolean)

    true on success

Raises:



20
21
22
23
24
25
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 20

def update_models(path, models)
  config = read_config(path)
  config["models"] = Array(models)
  write(path, config)
  true
end

.update_models_and_sync_date(path, models, date = Date.today, limits: nil) ⇒ Boolean

Update both models and last_synced in one operation

Parameters:

  • path (String)

    Path to config file

  • models (Array<String>)

    New list of model IDs

  • date (Date) (defaults to: Date.today)

    Date to set for last_synced

Returns:

  • (Boolean)

    true on success



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 67

def update_models_and_sync_date(path, models, date = Date.today, limits: nil)
  config = read_config(path)
  config["models"] = Array(models)
  config["last_synced"] = date

  unless limits.nil?
    normalized_limits = normalize_limits(limits)
    if normalized_limits.empty?
      config.delete("limits")
    else
      config["limits"] = normalized_limits
    end
    config.delete("context_limit")
  end

  write(path, config)
  true
end

.write(path, config) ⇒ Boolean

Write a complete config file

Parameters:

  • path (String)

    Path to config file

  • config (Hash)

    Config hash

Returns:

  • (Boolean)

    true on success



31
32
33
34
35
36
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 31

def write(path, config)
  ensure_directory(File.dirname(path))
  content = format_config(config)
  write_file(path, content)
  true
end