Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::ExtensionLoader
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::ExtensionLoader
- Defined in:
- lib/elastic_graph/schema_artifacts/runtime_metadata/extension_loader.rb
Overview
Responsible for loading extensions. This loader requires an interface definition (a class or module with empty method definitions that just serves to define what loaded extensions must implement). That allows us to verify the extension implements the interface correctly at load time, rather than deferring exceptions to when the extension is later used.
Note, however, that this does not guarantee no runtime exceptions from the use of the extension: the extension may return invalid return values, or throw exceptions when called. But this verifies the interface to the extent that we can.
Instance Method Summary collapse
-
#initialize(interface_def) ⇒ ExtensionLoader
constructor
A new instance of ExtensionLoader.
-
#load(constant_name, from:, config:) ⇒ Object
Loads the extension using the provided constant name, after requiring the ‘from` path.
Constructor Details
#initialize(interface_def) ⇒ ExtensionLoader
Returns a new instance of ExtensionLoader.
25 26 27 28 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension_loader.rb', line 25 def initialize(interface_def) @interface_def = interface_def @loaded_by_name = {} end |
Instance Method Details
#load(constant_name, from:, config:) ⇒ Object
Loads the extension using the provided constant name, after requiring the ‘from` path. Memoizes the result.
32 33 34 35 36 37 38 39 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension_loader.rb', line 32 def load(constant_name, from:, config:) (@loaded_by_name[constant_name] ||= load_extension(constant_name, from)).tap do |extension| if extension.require_path != from raise InvalidExtensionError, "Extension `#{constant_name}` cannot be loaded from `#{from}`, " \ "since it has already been loaded from `#{extension.require_path}`." end end.with(extension_config: config) end |