Module: ElasticGraph::Support::Config::ClassMethods
- Defined in:
- elasticgraph-support/lib/elastic_graph/support/config.rb
Overview
Defines class methods for configuration classes.
Instance Attribute Summary collapse
-
#path ⇒ ::String
readonly
Path from the global configuration root to where this configuration resides.
-
#required ⇒ ::Boolean
readonly
Whether this configuration property is required.
-
#validator ⇒ Support::JSONSchema::Validator
readonly
Validator for this configuration class.
Instance Method Summary collapse
-
#from_parsed_yaml(parsed_yaml) ⇒ ::Data?
Instantiates a config instance from the given parsed YAML class, returning
nil
if there is no config. -
#from_parsed_yaml!(parsed_yaml) ⇒ ::Data
Instantiates a config instance from the given parsed YAML class, raising an error if there is no config.
-
#json_schema(at:, optional:, **schema) ⇒ void
Defines the JSON schema and path for this configuration class.
Instance Attribute Details
#path ⇒ ::String (readonly)
Returns path from the global configuration root to where this configuration resides.
66 67 68 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 66 def path @path end |
#required ⇒ ::Boolean (readonly)
Returns whether this configuration property is required.
69 70 71 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 69 def required @required end |
#validator ⇒ Support::JSONSchema::Validator (readonly)
Returns validator for this configuration class.
63 64 65 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 63 def validator @validator end |
Instance Method Details
#from_parsed_yaml(parsed_yaml) ⇒ ::Data?
Instantiates a config instance from the given parsed YAML class, returning nil
if there is no config.
In addition, this (along with Support::FromYamlFile
) makes from_yaml_file(path_to_file)
available.
115 116 117 118 119 120 121 122 123 124 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 115 def from_parsed_yaml(parsed_yaml) value_at_path = Support::HashUtil.fetch_value_at_path(parsed_yaml, path.split(".")) { return nil } if value_at_path.is_a?(::Hash) config = (_ = value_at_path).transform_keys(&:to_sym) # : ::Hash[::Symbol, untyped] new(**config) else raise_invalid_config("Expected a hash at `#{path}`, got: `#{value_at_path.inspect}`.") end end |
#from_parsed_yaml!(parsed_yaml) ⇒ ::Data
Instantiates a config instance from the given parsed YAML class, raising an error if there is no config.
131 132 133 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 131 def from_parsed_yaml!(parsed_yaml) from_parsed_yaml(parsed_yaml) || raise_invalid_config("missing configuration at `#{path}`.") end |
#json_schema(at:, optional:, **schema) ⇒ void
This method returns an undefined value.
Defines the JSON schema and path for this configuration class.
99 100 101 102 103 104 105 106 107 108 |
# File 'elasticgraph-support/lib/elastic_graph/support/config.rb', line 99 def json_schema(at:, optional:, **schema) @path = at @required = !optional schema = Support::HashUtil.stringify_keys(schema) @validator = Support::JSONSchema::ValidatorFactory .new(schema: {"$schema" => "http://json-schema.org/draft-07/schema#", "$defs" => {"config" => schema}}, sanitize_pii: false) .with_unknown_properties_disallowed .validator_for("config") end |