Class: RubyCode::ConfigManager
- Inherits:
-
Object
- Object
- RubyCode::ConfigManager
- Defined in:
- lib/rubycode/config_manager.rb
Overview
Manages configuration persistence to ~/.rubycode/config.yml
Constant Summary collapse
- CONFIG_DIR =
File.join(Dir.home, ".rubycode")
- CONFIG_FILE =
File.join(CONFIG_DIR, "config.yml")
Class Method Summary collapse
-
.defaults_for_adapter(adapter) ⇒ Hash
Get default configuration for a given adapter.
-
.exists? ⇒ Boolean
Check if config file exists.
-
.load ⇒ Object
Load configuration from file Returns hash with symbolized keys or nil if file doesn't exist.
-
.save(config_hash) ⇒ Object
Save configuration to file.
Class Method Details
.defaults_for_adapter(adapter) ⇒ Hash
Get default configuration for a given adapter
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubycode/config_manager.rb', line 49 def defaults_for_adapter(adapter) case adapter when :groq { adapter: :groq, model: "llama-3.1-8b-instant", url: "https://api.groq.com/openai/v1/chat/completions" } else # Default to Ollama for unknown adapters { adapter: :ollama, model: "deepseek-r1:8b", url: "http://localhost:11434" } end end |
.exists? ⇒ Boolean
Check if config file exists
42 43 44 |
# File 'lib/rubycode/config_manager.rb', line 42 def exists? File.exist?(CONFIG_FILE) end |
.load ⇒ Object
Load configuration from file Returns hash with symbolized keys or nil if file doesn't exist
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubycode/config_manager.rb', line 15 def load return nil unless exists? yaml_content = File.read(CONFIG_FILE) config_hash = YAML.safe_load(yaml_content, permitted_classes: [Symbol]) # Symbolize keys symbolize_keys(config_hash) rescue StandardError => e warn "Warning: Failed to load config from #{CONFIG_FILE}: #{e.}" nil end |
.save(config_hash) ⇒ Object
Save configuration to file
30 31 32 33 34 35 36 37 38 |
# File 'lib/rubycode/config_manager.rb', line 30 def save(config_hash) FileUtils.mkdir_p(CONFIG_DIR) File.write(CONFIG_FILE, config_hash.to_yaml) true rescue StandardError => e warn "Warning: Failed to save config to #{CONFIG_FILE}: #{e.}" false end |