Class: OllamaChat::OllamaChatConfig

Inherits:
Object
  • Object
show all
Includes:
ComplexConfig, FileUtils
Defined in:
lib/ollama_chat/ollama_chat_config.rb

Constant Summary collapse

DEFAULT_CONFIG =
File.read(
  Pathname.new(__FILE__).dirname.join('ollama_chat_config/default_config.yml')
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ OllamaChatConfig

Returns a new instance of OllamaChatConfig.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ollama_chat/ollama_chat_config.rb', line 11

def initialize(filename = nil)
  @filename = filename || default_path
  unless File.directory?(cache_dir_path)
    mkdir_p cache_dir_path.to_s
  end
  @config = Provider.config(@filename, '⚙️')
  retried = false
rescue ConfigurationFileMissing
  if @filename == default_path && !retried
    retried = true
    mkdir_p config_dir_path.to_s
    File.secure_write(default_path, DEFAULT_CONFIG)
    retry
  else
    raise
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



31
32
33
# File 'lib/ollama_chat/ollama_chat_config.rb', line 31

def config
  @config
end

#filenameObject (readonly)

Returns the value of attribute filename.



29
30
31
# File 'lib/ollama_chat/ollama_chat_config.rb', line 29

def filename
  @filename
end

Instance Method Details

#cache_dir_pathObject



41
42
43
# File 'lib/ollama_chat/ollama_chat_config.rb', line 41

def cache_dir_path
  XDG.new.cache_home + 'ollama_chat'
end

#config_dir_pathObject



37
38
39
# File 'lib/ollama_chat/ollama_chat_config.rb', line 37

def config_dir_path
  XDG.new.config_home + 'ollama_chat'
end

#database_pathObject



45
46
47
# File 'lib/ollama_chat/ollama_chat_config.rb', line 45

def database_path
  cache_dir_path + 'documents.db'
end

#default_pathObject



33
34
35
# File 'lib/ollama_chat/ollama_chat_config.rb', line 33

def default_path
  config_dir_path + 'config.yml'
end