Module: OllamaAgent::GlobalDotenv
- Defined in:
- lib/ollama_agent/global_dotenv.rb
Overview
The ollama-client gem runs Dotenv.overload against the current working directory .env. When a global config file exists (XDG path or OLLAMA_AGENT_DOTENV_PATH), restore the environment from before that load and apply only that file so API keys are not picked up from arbitrary project trees.
Class Method Summary collapse
- .reconcile_after_ollama_client!(snapshot) ⇒ Object
- .resolved_path ⇒ Object
- .use_local_dotenv? ⇒ Boolean
- .xdg_config_home ⇒ Object
Class Method Details
.reconcile_after_ollama_client!(snapshot) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/ollama_agent/global_dotenv.rb', line 13 def reconcile_after_ollama_client!(snapshot) return if use_local_dotenv? return unless (path = resolved_path) && File.file?(path) ENV.replace(snapshot) Dotenv.overload(path) end |
.resolved_path ⇒ Object
25 26 27 28 29 30 |
# File 'lib/ollama_agent/global_dotenv.rb', line 25 def resolved_path custom = ENV["OLLAMA_AGENT_DOTENV_PATH"].to_s.strip return File.(custom) unless custom.empty? File.join(xdg_config_home, "ollama_agent", ".env") end |
.use_local_dotenv? ⇒ Boolean
21 22 23 |
# File 'lib/ollama_agent/global_dotenv.rb', line 21 def use_local_dotenv? ENV["OLLAMA_AGENT_USE_LOCAL_DOTENV"] == "1" end |
.xdg_config_home ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ollama_agent/global_dotenv.rb', line 32 def xdg_config_home base = ENV["XDG_CONFIG_HOME"].to_s.strip return File.(base) unless base.empty? File.(File.join(Dir.home, ".config")) end |