Module: TreeHaver::LanguageRegistry Private
- Defined in:
- lib/tree_haver/language_registry.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Thread-safe language registrations and cache for loaded Language handles
The LanguageRegistry provides two main functions:
-
Registrations: Store mappings from language names to backend-specific configurations
-
Cache: Memoize loaded Language objects to avoid repeated dlopen calls
The registry supports multiple backends for the same language, allowing runtime switching, benchmarking, and fallback scenarios.
Registration structure: }
Class Method Summary collapse
-
.clear_cache! ⇒ void
private
Clear the language cache.
-
.fetch(key) ⇒ Object
private
Fetch a cached language by key or compute and store it.
-
.register(name, backend_type, **config) ⇒ void
private
Register a language for a specific backend.
-
.registered(name, backend_type = nil) ⇒ Hash{Symbol => Hash}, ...
private
Fetch registration entries for a language.
Class Method Details
.clear_cache! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Clear the language cache
Removes all cached Language objects. The next call to fetch for any key will recompute the value. Does not clear registrations.
125 126 127 128 |
# File 'lib/tree_haver/language_registry.rb', line 125 def clear_cache! @mutex.synchronize { @cache.clear } nil end |
.fetch(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch a cached language by key or compute and store it
This method provides thread-safe memoization for loaded Language objects. If the key exists in the cache, the cached value is returned immediately. Otherwise, the block is called to compute the value, which is then cached.
109 110 111 112 113 114 115 |
# File 'lib/tree_haver/language_registry.rb', line 109 def fetch(key) @mutex.synchronize do return @cache[key] if @cache.key?(key) value = yield @cache[key] = value end end |
.register(name, backend_type, **config) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Register a language for a specific backend
Stores backend-specific configuration for a language. Multiple backends can be registered for the same language without conflict.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tree_haver/language_registry.rb', line 56 def register(name, backend_type, **config) key = name.to_sym backend_key = backend_type.to_sym @mutex.synchronize do @registrations[key] ||= {} @registrations[key][backend_key] = config.compact end nil end |
.registered(name, backend_type = nil) ⇒ Hash{Symbol => Hash}, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch registration entries for a language
Returns all backend-specific configurations for a language.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tree_haver/language_registry.rb', line 83 def registered(name, backend_type = nil) @mutex.synchronize do lang_config = @registrations[name.to_sym] return unless lang_config if backend_type lang_config[backend_type.to_sym] else lang_config end end end |