Class: LanguageOperator::Config::ToolRegistry
- Inherits:
-
Object
- Object
- LanguageOperator::Config::ToolRegistry
- Defined in:
- lib/language_operator/config/tool_registry.rb
Overview
Fetches and caches tool registry from remote URL
Constant Summary collapse
- REGISTRY_URL =
'https://raw.githubusercontent.com/language-operator/language-tools/main/index.yaml'- CACHE_TTL =
1 hour
3600
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Clear the cache to force a fresh fetch.
-
#fetch ⇒ Hash
Fetch tools from registry with caching.
-
#initialize(registry_url: REGISTRY_URL, api_token: nil) ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
Constructor Details
#initialize(registry_url: REGISTRY_URL, api_token: nil) ⇒ ToolRegistry
Returns a new instance of ToolRegistry.
14 15 16 17 18 19 |
# File 'lib/language_operator/config/tool_registry.rb', line 14 def initialize(registry_url: REGISTRY_URL, api_token: nil) @registry_url = registry_url @api_token = api_token || ENV.fetch('GITHUB_TOKEN', nil) @cache = nil @cache_time = nil end |
Instance Method Details
#clear_cache ⇒ Object
Clear the cache to force a fresh fetch
36 37 38 39 |
# File 'lib/language_operator/config/tool_registry.rb', line 36 def clear_cache @cache = nil @cache_time = nil end |
#fetch ⇒ Hash
Fetch tools from registry with caching
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/language_operator/config/tool_registry.rb', line 24 def fetch # Return cached data if still valid return @cache if @cache && @cache_time && (Time.now - @cache_time) < CACHE_TTL # Fetch from remote (no fallback) tools = fetch_remote @cache = tools @cache_time = Time.now tools end |