Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::Extension
- Inherits:
-
Data
- Object
- Data
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::Extension
- Defined in:
- lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb
Overview
Represents an extension–a class or module (potentially from outside the ElasticGraph code base) that implements a standard interface to plug in custom functionality.
Extensions are serialized using two fields:
-
‘name`: the Ruby constant of the extension
-
‘require_path`: file path to `require` to load the extension
However, an ‘Extension` instance represents a loaded, resolved extension. We eagerly load extensions (and validate them in the `ExtensionLoader`) in order to surface any issues with the extension as soon as possible. We don’t want to defer errors if we can detect any issues with the extension at boot time.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#extension_class ⇒ Object
readonly
Returns the value of attribute extension_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#require_path ⇒ Object
readonly
Returns the value of attribute require_path.
Class Method Summary collapse
-
.load_from_hash(hash, via:) ⇒ Object
Loads an extension using a serialized hash, via the provided ‘ExtensionLoader`.
Instance Method Summary collapse
-
#initialize(extension_class:, require_path:, config:, name: extension_class.name.to_s) ⇒ Extension
constructor
A new instance of Extension.
-
#to_dumpable_hash ⇒ Object
The serialized form of an extension.
- #verify_against(interface_def) ⇒ Object
- #verify_against!(interface_def) ⇒ Object
Constructor Details
#initialize(extension_class:, require_path:, config:, name: extension_class.name.to_s) ⇒ Extension
Returns a new instance of Extension.
30 31 32 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 30 def initialize(extension_class:, require_path:, config:, name: extension_class.name.to_s) super(extension_class:, require_path:, config:, name:) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config
28 29 30 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 28 def config @config end |
#extension_class ⇒ Object (readonly)
Returns the value of attribute extension_class
28 29 30 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 28 def extension_class @extension_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name
28 29 30 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 28 def name @name end |
#require_path ⇒ Object (readonly)
Returns the value of attribute require_path
28 29 30 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 28 def require_path @require_path end |
Class Method Details
.load_from_hash(hash, via:) ⇒ Object
Loads an extension using a serialized hash, via the provided ‘ExtensionLoader`.
35 36 37 38 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 35 def self.load_from_hash(hash, via:) config = Support::HashUtil.symbolize_keys(hash["config"] || {}) # : ::Hash[::Symbol, untyped] via.load(hash.fetch("name"), from: hash.fetch("require_path"), config: config) end |
Instance Method Details
#to_dumpable_hash ⇒ Object
The serialized form of an extension.
41 42 43 44 45 46 47 48 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 41 def to_dumpable_hash # Keys here are ordered alphabetically; please keep them that way. { "config" => Support::HashUtil.stringify_keys(config), "name" => name, "require_path" => require_path }.reject { |_, v| v.empty? } end |
#verify_against(interface_def) ⇒ Object
54 55 56 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 54 def verify_against(interface_def) InterfaceVerifier.verify(extension_class, against: interface_def, constant_name: name) end |
#verify_against!(interface_def) ⇒ Object
50 51 52 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb', line 50 def verify_against!(interface_def) InterfaceVerifier.verify!(extension_class, against: interface_def, constant_name: name) end |