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) ⇒ 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
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) = 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
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
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
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
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 |