Class: Locallingo::Settings
- Inherits:
-
Object
- Object
- Locallingo::Settings
- Defined in:
- lib/locallingo/settings.rb
Overview
Code-level gem settings, configured via Locallingo.configure. Distinct
from Locallingo::Configuration, which loads the .locallingo.yml project
file — Settings holds what must never live in YAML: provider credentials.
Locallingo.configure do |config|
config.anthropic_api_key = ENV.fetch("MY_KEY") # a String…
config.openai_api_key = -> { Vault.read("openai_key") } # …or a callable
end
Callables are resolved lazily on every use (never memoized), so keys can come from sources that aren't ready at configure time or that rotate.
Constant Summary collapse
- PROVIDERS =
%i[openai anthropic gemini deepseek openrouter].freeze
Instance Method Summary collapse
-
#api_key_for(provider) ⇒ Object
The usable key for
provider: callables are called, results stripped, and blank or unknown-provider values come back as nil.
Instance Method Details
#api_key_for(provider) ⇒ Object
The usable key for provider: callables are called, results stripped,
and blank or unknown-provider values come back as nil.
22 23 24 25 26 27 28 29 |
# File 'lib/locallingo/settings.rb', line 22 def api_key_for(provider) return nil unless PROVIDERS.include?(provider.to_sym) value = public_send("#{provider}_api_key") value = value.call if value.respond_to?(:call) key = value.to_s.strip key.empty? ? nil : key end |