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
-
#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.
-
#state_home_path ⇒ String
Returns the path to the state directory, where the documents database for RAG is stored.
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 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 40 def initialize(filename = nil) @filename = filename || default_path state_home_path.mkpath @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.
62 63 64 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 62 def config @config end |
#filename ⇒ Object (readonly)
The filename reader returns the name of the file associated with this instance.
57 58 59 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 57 def filename @filename end |
Instance Method Details
#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.
87 88 89 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 87 def config_dir_path OC::XDG_CONFIG_HOME 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’.
103 104 105 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 103 def database_path state_home_path + 'documents.db' end |
#default_config_path ⇒ String
The default_config_path method returns the path to the default configuration file.
68 69 70 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 68 def default_config_path DEFAULT_CONFIG_PATH end |
#default_path ⇒ Pathname
The default_path method constructs the full path to the default configuration file.
77 78 79 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 77 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.
112 113 114 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 112 def diff_tool OC::DIFF_TOOL? end |
#state_home_path ⇒ String
Returns the path to the state directory, where the documents database for RAG is stored.
95 96 97 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 95 def state_home_path OC::XDG_STATE_HOME end |