Class: RubyAiGemContext::ConfigFile
- Inherits:
-
Object
- Object
- RubyAiGemContext::ConfigFile
- Defined in:
- lib/ruby_ai_gem_context/config_file.rb
Overview
Tracks generated context files in .ai_context/config.yml
This helps us know:
- Which files we generated vs user-created
- When they were generated
- Which model was used
Constant Summary collapse
- CONFIG_FILENAME =
"config.yml"
Instance Attribute Summary collapse
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Instance Method Summary collapse
- #config_dir ⇒ Object
- #config_path ⇒ Object
-
#generated?(platform_key) ⇒ Boolean
Check if we generated a specific platform's file.
-
#generated_info(platform_key) ⇒ Object
Get info about a generated file.
-
#generated_platforms ⇒ Object
List all platforms we've generated files for.
-
#initialize(project_root = Dir.pwd) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
-
#load ⇒ Object
Load existing config or return empty structure.
-
#record_generated(platform_key, model: nil) ⇒ Object
Record that a file was generated.
-
#record_source_folders(folders) ⇒ Object
Record source folders used for generation.
-
#save(config) ⇒ Object
Save config to file.
-
#source_folders ⇒ Object
Get previously used source folders.
Constructor Details
#initialize(project_root = Dir.pwd) ⇒ ConfigFile
15 16 17 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 15 def initialize(project_root = Dir.pwd) @project_root = project_root end |
Instance Attribute Details
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
13 14 15 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 13 def project_root @project_root end |
Instance Method Details
#config_dir ⇒ Object
19 20 21 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 19 def config_dir File.join(project_root, RubyAiGemContext.configuration.config_dir) end |
#config_path ⇒ Object
23 24 25 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 23 def config_path File.join(config_dir, CONFIG_FILENAME) end |
#generated?(platform_key) ⇒ Boolean
Check if we generated a specific platform's file
55 56 57 58 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 55 def generated?(platform_key) config = load config.dig("generated", platform_key.to_s).is_a?(Hash) end |
#generated_info(platform_key) ⇒ Object
Get info about a generated file
61 62 63 64 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 61 def generated_info(platform_key) config = load config.dig("generated", platform_key.to_s) end |
#generated_platforms ⇒ Object
List all platforms we've generated files for
67 68 69 70 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 67 def generated_platforms config = load (config["generated"] || {}).keys.map(&:to_sym) end |
#load ⇒ Object
Load existing config or return empty structure
28 29 30 31 32 33 34 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 28 def load return default_config unless File.exist?(config_path) YAML.safe_load(File.read(config_path), permitted_classes: [Time, Symbol]) || default_config rescue StandardError default_config end |
#record_generated(platform_key, model: nil) ⇒ Object
Record that a file was generated
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 43 def record_generated(platform_key, model: nil) config = load config["generated"] ||= {} config["generated"][platform_key.to_s] = { "created_at" => Time.now.utc.iso8601, "model" => model || RubyAiGemContext.configuration.model, "path" => RubyAiGemContext.platform(platform_key).path } save(config) end |
#record_source_folders(folders) ⇒ Object
Record source folders used for generation
73 74 75 76 77 78 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 73 def record_source_folders(folders) config = load config["source_folders"] = folders config["last_generated_at"] = Time.now.utc.iso8601 save(config) end |
#save(config) ⇒ Object
Save config to file
37 38 39 40 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 37 def save(config) FileUtils.mkdir_p(config_dir) File.write(config_path, YAML.dump(config)) end |
#source_folders ⇒ Object
Get previously used source folders
81 82 83 84 |
# File 'lib/ruby_ai_gem_context/config_file.rb', line 81 def source_folders config = load config["source_folders"] end |