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



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

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:



57
58
59
60
61
62
63
64
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 57

def update_last_synced(path, date = Date.today)
  content = read_file_content(path)
  raise ConfigError, "Config file not found: #{path}" unless content

  updated_content = replace_or_add_field(content, "last_synced", date.to_s)
  write_file(path, updated_content)
  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
26
27
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 20

def update_models(path, models)
  content = read_file_content(path)
  raise ConfigError, "Config file not found: #{path}" unless content

  updated_content = replace_models_section(content, models)
  write_file(path, updated_content)
  true
end

.update_models_and_sync_date(path, models, date = Date.today) ⇒ 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

Raises:



71
72
73
74
75
76
77
78
79
# File 'lib/ace/support/models/atoms/provider_config_writer.rb', line 71

def update_models_and_sync_date(path, models, date = Date.today)
  content = read_file_content(path)
  raise ConfigError, "Config file not found: #{path}" unless content

  updated_content = replace_models_section(content, models)
  updated_content = replace_or_add_field(updated_content, "last_synced", date.to_s)
  write_file(path, updated_content)
  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



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

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