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

The initialize method sets up the configuration file path and ensures the cache directory exists. It attempts to load configuration from the specified filename or uses a default path. If the configuration file is missing and the default path is used, it creates the necessary directory structure and writes a default configuration file.

Parameters:

  • filename (String, nil) (defaults to: nil)

    the path to the configuration file



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ollama_chat/ollama_chat_config.rb', line 21

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

#configComplexConfig::Settings (readonly)

The config reader returns the configuration object for the chat instance.

Returns:

  • (ComplexConfig::Settings)

    the configuration object



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

def config
  @config
end

#filenameObject (readonly)

The filename reader returns the name of the file associated with this instance.



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

def filename
  @filename
end

Instance Method Details

#cache_dir_pathPathname

The cache_dir_path method returns the path to the ollama_chat cache directory within the XDG cache home directory.

Returns:

  • (Pathname)

    the pathname object representing the cache directory path



78
79
80
# File 'lib/ollama_chat/ollama_chat_config.rb', line 78

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

#config_dir_pathPathname

The config_dir_path method returns the path to the ollama_chat configuration directory by combining the XDG config home directory with the ‘ollama_chat’ subdirectory.

directory

Returns:

  • (Pathname)

    the pathname object representing the configuration



70
71
72
# File 'lib/ollama_chat/ollama_chat_config.rb', line 70

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

#database_pathPathname

The database_path method constructs the full path to the documents database file by joining the cache directory path with the filename ‘documents.db’.

Returns:

  • (Pathname)

    the full path to the documents database file



86
87
88
# File 'lib/ollama_chat/ollama_chat_config.rb', line 86

def database_path
  cache_dir_path + 'documents.db'
end

#default_config_pathString

The default_config_path method returns the path to the default configuration file.

Returns:

  • (String)

    the path to the default configuration file



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

def default_config_path
  DEFAULT_CONFIG_PATH
end

#default_pathPathname

The default_path method constructs the full path to the default configuration file.

config.yml file within the configuration directory

Returns:

  • (Pathname)

    a Pathname object representing the path to the



60
61
62
# File 'lib/ollama_chat/ollama_chat_config.rb', line 60

def default_path
  config_dir_path + 'config.yml'
end

#diff_toolString

The diff_tool method returns the preferred diff tool command. It checks for the DIFF_TOOL environment variable and falls back to ‘vimdiff’ if not set.

Returns:

  • (String)

    the command name of the diff tool to be used



95
96
97
# File 'lib/ollama_chat/ollama_chat_config.rb', line 95

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