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_PATH =
Pathname.new(__FILE__).dirname.
join('ollama_chat_config/default_config.yml')
DEFAULT_CONFIG =
File.read(DEFAULT_CONFIG_PATH)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ OllamaChatConfig

Returns a new instance of OllamaChatConfig.



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

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.



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

def config
  @config
end

#filenameObject (readonly)

Returns the value of attribute filename.



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

def filename
  @filename
end

Instance Method Details

#cache_dir_pathObject



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

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

#config_dir_pathObject



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

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

#database_pathObject



50
51
52
# File 'lib/ollama_chat/ollama_chat_config.rb', line 50

def database_path
  cache_dir_path + 'documents.db'
end

#default_config_pathObject



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

def default_config_path
  DEFAULT_CONFIG_PATH
end

#default_pathObject



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

def default_path
  config_dir_path + 'config.yml'
end

#diff_toolObject



54
55
56
# File 'lib/ollama_chat/ollama_chat_config.rb', line 54

def diff_tool
  ENV.fetch('DIFF_TOOL', 'vimdiff')
end