Class: Ace::Support::Models::Atoms::ProviderConfigWriter
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::ProviderConfigWriter
- 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
-
.backup(path) ⇒ String
Create a backup of a config file.
-
.update_last_synced(path, date = Date.today) ⇒ Boolean
Update the last_synced field in a provider config file.
-
.update_models(path, models) ⇒ Boolean
Update the models list in a provider config file.
-
.update_models_and_sync_date(path, models, date = Date.today, limits: nil) ⇒ Boolean
Update both models and last_synced in one operation.
-
.write(path, config) ⇒ Boolean
Write a complete config file.
Class Method Details
.backup(path) ⇒ String
Create a backup of a config 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) = Time.now.strftime("%Y%m%d_%H%M%S") backup_path = "#{path}.backup.#{}" 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
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
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
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
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 |