Sha256: 28c0e9ad370b32ac9834ded3043aaccec9b471852e444cd8029c487b2cd1c2d3

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "yaml"
require "dry/files"

module Vercon
  class Config
    CLAUDE_MODELS = %w[
      claude-3-haiku-20240307
      claude-3-sonnet-20240229
      claude-3-opus-20240229
    ].freeze
    DEFAULT_CLAUDE_MODEL = "claude-3-sonnet-20240229"
    LOWEST_CLAUDE_MODEL = "claude-3-haiku-20240307"
    PATH = "~/.vercon.yml"

    def initialize
      @files = Dry::Files.new
      @config = YAML.load_file(@files.expand_path(PATH))
    rescue Errno::ENOENT
      @config = {}
    end

    def exists?
      !@config.empty?
    end

    def claude_token
      @config["claude_token"]
    end

    def claude_model
      @config["claude_model"]
    end

    def open_by_default?
      @config["open_by_default"].nil? ? false : @config["open_by_default"]
    end

    %i[claude_token claude_model open_by_default].each do |method|
      define_method(:"#{method}=") do |value|
        @config[method.to_s] = value
        write_config
      end
    end

    private

    def write_config
      @files.write(@files.expand_path(PATH), YAML.safe_dump(@config))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vercon-0.0.3 lib/vercon/config.rb
vercon-0.0.2 lib/vercon/config.rb