Class: CodeSage::Config
- Inherits:
-
Object
- Object
- CodeSage::Config
- Defined in:
- lib/code_sage/config.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ 'llm' => { 'provider' => 'openai', # openai, ollama, qwen, gemini 'model' => 'gpt-4', 'temperature' => 0.1, 'max_tokens' => 2000, 'api_key' => nil # Will use ENV variables }, 'git' => { 'default_branch' => 'main', 'include_patterns' => ['*.rb', '*.rake', 'Gemfile', 'Rakefile'], 'exclude_patterns' => ['spec/**/*', 'test/**/*'] }, 'review' => { 'focus_areas' => ['security', 'performance', 'maintainability', 'best_practices'], 'severity_levels' => ['low', 'medium', 'high', 'critical'] }, 'output' => { 'format' => 'console', 'verbose' => false, 'colors' => true }, 'auto_fix' => { 'enabled' => false, 'confirm_before_apply' => true, 'create_backups' => true, 'backup_extension' => '.backup' } }.freeze
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #config_info ⇒ Object
- #get(key_path) ⇒ Object
-
#initialize(config_path = nil) ⇒ Config
constructor
A new instance of Config.
- #reset! ⇒ Object
- #save! ⇒ Object
- #set(key_path, value) ⇒ Object
- #show_config_info ⇒ Object
Constructor Details
#initialize(config_path = nil) ⇒ Config
Returns a new instance of Config.
37 38 39 40 |
# File 'lib/code_sage/config.rb', line 37 def initialize(config_path = nil) @config_path = config_path || default_config_path @data = load_config end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
35 36 37 |
# File 'lib/code_sage/config.rb', line 35 def config_path @config_path end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
35 36 37 |
# File 'lib/code_sage/config.rb', line 35 def data @data end |
Instance Method Details
#config_info ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/code_sage/config.rb', line 63 def config_info if File.exist?(@config_path) "Using config file: #{@config_path}" else "No config file found, using defaults" end end |
#get(key_path) ⇒ Object
42 43 44 45 |
# File 'lib/code_sage/config.rb', line 42 def get(key_path) keys = key_path.split('.') keys.reduce(@data) { |config, key| config&.dig(key) } end |
#reset! ⇒ Object
58 59 60 61 |
# File 'lib/code_sage/config.rb', line 58 def reset! @data = DEFAULT_CONFIG.dup save! end |
#save! ⇒ Object
54 55 56 |
# File 'lib/code_sage/config.rb', line 54 def save! File.write(@config_path, YAML.dump(@data)) end |
#set(key_path, value) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/code_sage/config.rb', line 47 def set(key_path, value) keys = key_path.split('.') last_key = keys.pop target = keys.reduce(@data) { |config, key| config[key] ||= {} } target[last_key] = value end |
#show_config_info ⇒ Object
71 72 73 |
# File 'lib/code_sage/config.rb', line 71 def show_config_info puts "📋 #{config_info}".colorize(:cyan) end |