Class: GitAuto::Config::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/git_auto/config/settings.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

CONFIG_DIR =
File.expand_path("~/.git_auto")
CONFIG_FILE =
File.join(CONFIG_DIR, "config.yml")
SUPPORTED_PROVIDERS =
{
  "claude" => {
    name: "Anthropic (Claude 3.5 Sonnet, Claude 3.5 Haiku)",
    models: {
      "Claude 3.5 Sonnet" => "claude-3-5-sonnet-latest",
      "Claude 3.5 Haiku" => "claude-3-5-haiku-latest"
    }
  },
  "openai" => {
    name: "OpenAI (GPT-4o, GPT-4o mini)",
    models: {
      "GPT-4o" => "gpt-4o",
      "GPT-4o mini" => "gpt-4o-mini"
    }
  }
}.freeze
DEFAULT_SETTINGS =
{
  commit_style: "conventional",
  ai_provider: "openai",
  ai_model: "gpt-4o",
  show_diff: true,
  save_history: true,
  max_retries: 3
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



40
41
42
43
# File 'lib/git_auto/config/settings.rb', line 40

def initialize
  ensure_config_dir
  @settings = load_settings
end

Instance Method Details

#allObject



55
56
57
# File 'lib/git_auto/config/settings.rb', line 55

def all
  @settings
end

#available_modelsObject



63
64
65
# File 'lib/git_auto/config/settings.rb', line 63

def available_models
  provider_info[:models]
end

#get(key) ⇒ Object



51
52
53
# File 'lib/git_auto/config/settings.rb', line 51

def get(key)
  @settings[key.to_sym]
end

#provider_infoObject



59
60
61
# File 'lib/git_auto/config/settings.rb', line 59

def provider_info
  SUPPORTED_PROVIDERS[get(:ai_provider)]
end

#save(options = {}) ⇒ Object



45
46
47
48
49
# File 'lib/git_auto/config/settings.rb', line 45

def save(options = {})
  validate_settings!(options)
  @settings = @settings.merge(options)
  File.write(CONFIG_FILE, YAML.dump(@settings))
end