Class: Parabot::Configuration
- Inherits:
-
Object
- Object
- Parabot::Configuration
- Defined in:
- lib/parabot/configuration.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Class Method Summary collapse
Instance Method Summary collapse
- #all_language_extensions ⇒ Object
- #all_language_project_files ⇒ Object
- #custom_commands ⇒ Object
-
#initialize(project_root = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #language ⇒ Object
- #load_config(file = nil) ⇒ Object
- #log_file ⇒ Object
-
#log_level ⇒ Object
Configuration accessors.
- #messaging_adapter ⇒ Object
-
#system_prompt(detected_languages = []) ⇒ Object
Always returns: base_prompt + language_specific_addition.
- #test_analysis_prompt ⇒ Object
- #test_command(language) ⇒ Object
- #test_guidance(language) ⇒ Object
Constructor Details
#initialize(project_root = nil) ⇒ Configuration
Returns a new instance of Configuration.
29 30 31 32 |
# File 'lib/parabot/configuration.rb', line 29 def initialize(project_root = nil) @project_root = project_root || Dir.pwd setup_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/parabot/configuration.rb', line 27 def config @config end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
27 28 29 |
# File 'lib/parabot/configuration.rb', line 27 def project_root @project_root end |
Class Method Details
.current ⇒ Object
18 19 20 |
# File 'lib/parabot/configuration.rb', line 18 def current @instance || load end |
.load(file = nil, project_root = nil) ⇒ Object
14 15 16 |
# File 'lib/parabot/configuration.rb', line 14 def load(file = nil, project_root = nil) @instance ||= new(project_root).tap { |config| config.load_config(file) } end |
.reset! ⇒ Object
22 23 24 |
# File 'lib/parabot/configuration.rb', line 22 def reset! @instance = nil end |
Instance Method Details
#all_language_extensions ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/parabot/configuration.rb', line 68 def all_language_extensions return {} unless config.languages @all_language_extensions ||= config.languages.map do |lang, lang_config| extensions = lang_config&.file_extensions&.to_a || [] [lang, extensions] unless extensions.empty? end.compact.to_h end |
#all_language_project_files ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/parabot/configuration.rb', line 78 def all_language_project_files return {} unless config.languages result = {} config.languages.each do |lang, lang_config| project_files = lang_config&.project_files&.to_a || [] result[lang] = project_files unless project_files.empty? end result rescue StandardError {} end |
#custom_commands ⇒ Object
60 61 62 |
# File 'lib/parabot/configuration.rb', line 60 def custom_commands config.commands&.to_h || {} end |
#language ⇒ Object
64 65 66 |
# File 'lib/parabot/configuration.rb', line 64 def language config.language || "auto" end |
#load_config(file = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/parabot/configuration.rb', line 34 def load_config(file = nil) files = file ? resolve_config_file_path(file) : config_files Config.load_and_set_settings(*files) @config = Settings rescue StandardError => e raise ConfigurationError, "Failed to load configuration: #{e.}" end |
#log_file ⇒ Object
50 51 52 |
# File 'lib/parabot/configuration.rb', line 50 def log_file config.log_file || "stderr" end |
#log_level ⇒ Object
Configuration accessors
46 47 48 |
# File 'lib/parabot/configuration.rb', line 46 def log_level config.log_level&.to_sym || :warn end |
#messaging_adapter ⇒ Object
123 124 125 |
# File 'lib/parabot/configuration.rb', line 123 def messaging_adapter config.adapter&.to_sym || :tmux end |
#system_prompt(detected_languages = []) ⇒ Object
Always returns: base_prompt + language_specific_addition
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/parabot/configuration.rb', line 92 def system_prompt(detected_languages = []) base_prompt = config.system_prompt || "" languages = Array(detected_languages) language_addition = languages.map do |lang| language_specific_system_prompt(lang) end.reject(&:empty?).join("\n") base_prompt + maybe_multi_language_notice(languages) + language_addition end |
#test_analysis_prompt ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/parabot/configuration.rb', line 104 def test_analysis_prompt test_guidance = config.test_guidance template = <<~TEMPLATE Analyze TEST RESULTS: <test_results_file> {{results}} </test_results_file> #{test_guidance} TEMPLATE template.strip end |
#test_command(language) ⇒ Object
54 55 56 57 58 |
# File 'lib/parabot/configuration.rb', line 54 def test_command(language) # Get test command from language-specific configuration lang_config = config.languages&.public_send(language.to_sym) lang_config&.test_command end |
#test_guidance(language) ⇒ Object
119 120 121 |
# File 'lib/parabot/configuration.rb', line 119 def test_guidance(language) config.languages&.public_send(language.to_s)&.test_guidance end |