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"
    }
  },
  "gemini" => {
    name: "Google (Gemini 2.5 Flash)",
    models: {
      "Gemini 2.5 Flash Preview" => "gemini-2.5-flash-preview-05-20"
    }
  }
}.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.



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

def initialize
  ensure_config_dir
  @settings = load_settings
end

Instance Method Details

#allObject



66
67
68
# File 'lib/git_auto/config/settings.rb', line 66

def all
  @settings
end

#available_modelsObject



74
75
76
# File 'lib/git_auto/config/settings.rb', line 74

def available_models
  provider_info[:models]
end

#get(key) ⇒ Object



57
58
59
# File 'lib/git_auto/config/settings.rb', line 57

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

#provider_infoObject



70
71
72
# File 'lib/git_auto/config/settings.rb', line 70

def provider_info
  SUPPORTED_PROVIDERS[get(:ai_provider)]
end

#save(options = {}) ⇒ Object



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

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

#set(key, value) ⇒ Object



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

def set(key, value)
  @settings[key.to_sym] = value
  save
end