Class: OllamaChat::OllamaChatConfig
- Inherits:
-
Object
- Object
- OllamaChat::OllamaChatConfig
- Includes:
- ComplexConfig, FileUtils
- Defined in:
- lib/ollama_chat/ollama_chat_config.rb
Overview
A configuration class for managing OllamaChat settings and file paths.
This class handles the initialization and management of configuration files for the OllamaChat application. It provides methods for setting up default configurations, determining appropriate file paths for config and cache directories, and managing the loading and creation of configuration files based on XDG standards.
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
Path to the default config
Pathname.new(__FILE__).dirname. join('ollama_chat_config/default_config.yml')
- DEFAULT_CONFIG =
Content of the default config
File.read(DEFAULT_CONFIG_PATH)
Instance Attribute Summary collapse
-
#config ⇒ ComplexConfig::Settings
readonly
The config reader returns the configuration object for the chat instance.
-
#filename ⇒ Object
readonly
The filename reader returns the name of the file associated with this instance.
Instance Method Summary collapse
-
#cache_dir_path ⇒ Pathname
The cache_dir_path method returns the path to the ollama_chat cache directory within the XDG cache home directory.
-
#config_dir_path ⇒ Pathname
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.
-
#database_path ⇒ Pathname
The database_path method constructs the full path to the documents database file by joining the cache directory path with the filename ‘documents.db’.
-
#default_config_path ⇒ String
The default_config_path method returns the path to the default configuration file.
-
#default_path ⇒ Pathname
The default_path method constructs the full path to the default configuration file.
-
#diff_tool ⇒ String
The diff_tool method returns the preferred diff tool command.
-
#initialize(filename = nil) ⇒ OllamaChatConfig
constructor
The initialize method sets up the configuration file path and ensures the cache directory exists.
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 40 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
#config ⇒ ComplexConfig::Settings (readonly)
The config reader returns the configuration object for the chat instance.
64 65 66 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 64 def config @config end |
#filename ⇒ Object (readonly)
The filename reader returns the name of the file associated with this instance.
59 60 61 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 59 def filename @filename end |
Instance Method Details
#cache_dir_path ⇒ Pathname
The cache_dir_path method returns the path to the ollama_chat cache directory within the XDG cache home directory.
97 98 99 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 97 def cache_dir_path XDG.new.cache_home + 'ollama_chat' end |
#config_dir_path ⇒ Pathname
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
89 90 91 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 89 def config_dir_path XDG.new.config_home + 'ollama_chat' end |
#database_path ⇒ Pathname
The database_path method constructs the full path to the documents database file by joining the cache directory path with the filename ‘documents.db’.
105 106 107 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 105 def database_path cache_dir_path + 'documents.db' end |
#default_config_path ⇒ String
The default_config_path method returns the path to the default configuration file.
70 71 72 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 70 def default_config_path DEFAULT_CONFIG_PATH end |
#default_path ⇒ Pathname
The default_path method constructs the full path to the default configuration file.
config.yml file within the configuration directory
79 80 81 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 79 def default_path config_dir_path + 'config.yml' end |
#diff_tool ⇒ String
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.
114 115 116 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 114 def diff_tool ENV.fetch('DIFF_TOOL', 'vimdiff') end |