Class: Aiko::Config

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

Constant Summary collapse

DEFAULTS =
{
  base_url: "https://api.deepseek.com",
  model: "deepseek-v4-flash",
  max_iterations: 20
}.freeze
FILE_KEYS =
%w[base_url model max_iterations].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url:, model:, max_iterations:, workdir: nil) ⇒ Config

Returns a new instance of Config.



45
46
47
48
49
50
51
52
# File 'lib/aiko/config.rb', line 45

def initialize(api_key:, base_url:, model:, max_iterations:, workdir: nil)
  @api_key = api_key
  @base_url = base_url
  @model = model
  @max_iterations = max_iterations
  @workdir = File.expand_path(workdir || Dir.pwd)
  validate!
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



15
16
17
# File 'lib/aiko/config.rb', line 15

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



15
16
17
# File 'lib/aiko/config.rb', line 15

def base_url
  @base_url
end

#max_iterationsObject (readonly)

Returns the value of attribute max_iterations.



15
16
17
# File 'lib/aiko/config.rb', line 15

def max_iterations
  @max_iterations
end

#modelObject (readonly)

Returns the value of attribute model.



15
16
17
# File 'lib/aiko/config.rb', line 15

def model
  @model
end

#workdirObject (readonly)

Returns the value of attribute workdir.



15
16
17
# File 'lib/aiko/config.rb', line 15

def workdir
  @workdir
end

Class Method Details

.default_config_pathObject



32
33
34
# File 'lib/aiko/config.rb', line 32

def self.default_config_path
  File.join(Dir.home, ".aiko", "config.json")
end

.load(cli_options = {}, config_path: default_config_path, env: ENV) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aiko/config.rb', line 17

def self.load(cli_options = {}, config_path: default_config_path, env: ENV)
  file = load_file(config_path)
  merged = DEFAULTS.dup
  FILE_KEYS.each do |key|
    merged[key.to_sym] = file[key] if file.key?(key)
  end
  merged[:base_url] = env["AIKO_BASE_URL"] if env["AIKO_BASE_URL"]
  merged[:model] = env["AIKO_MODEL"] if env["AIKO_MODEL"]
  merged[:api_key] = env["AIKO_API_KEY"]
  %i[api_key base_url model max_iterations workdir].each do |key|
    merged[key] = cli_options[key] if cli_options.key?(key) && !cli_options[key].nil?
  end
  new(**merged)
end