Class: OllamaChat::OllamaChatConfig
- Inherits:
-
Object
- Object
- OllamaChat::OllamaChatConfig
- 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
-
#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.
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
#config ⇒ ComplexConfig::Settings (readonly)
The config reader returns the configuration object for the chat instance.
45 46 47 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 45 def config @config end |
#filename ⇒ Object (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_path ⇒ Pathname
The cache_dir_path method returns the path to the ollama_chat cache directory within the XDG cache home directory.
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_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
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_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’.
86 87 88 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 86 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.
51 52 53 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 51 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
60 61 62 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 60 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.
95 96 97 |
# File 'lib/ollama_chat/ollama_chat_config.rb', line 95 def diff_tool ENV.fetch('DIFF_TOOL', 'vimdiff') end |