Class: LanguageOperator::Config::ToolRegistry

Inherits:
Object
  • Object
show all
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

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_cacheObject

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

#fetchHash

Fetch tools from registry with caching

Returns:

  • (Hash)

    Tool configurations keyed by tool name



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