Module: ElasticGraph::Support::Config::InstanceMethods

Defined in:
lib/elastic_graph/support/config.rb

Instance Method Summary collapse

Instance Method Details

#initialize(**config) ⇒ Object

Overrides ‘initialize` to apply JSON schema validation.



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/elastic_graph/support/config.rb', line 155

def initialize(**config)
  klass = (_ = self.class) # : ClassMethods[::Data]
  validator = klass.validator
  config = validator.merge_defaults(config)

  if (error = validator.validate_with_error_message(config))
    klass.raise_invalid_config(error)
  end

  config = config.transform_keys(&:to_sym)
  __skip__ = super(**convert_values(**config))
end

#with(**updates) ⇒ Object

Overrides ‘#with` to bypass the normal JSON schema validation that applies in `#initialize`. This is required so that `config.with(…)` can be used on config classes that use the `convert_values` hook to convert JSON data to some custom Ruby type. The custom Ruby type won’t pass JSON schema validation, and if we didn’t override ‘with` then we’d get validation failures due to the converted values failing validation.



173
174
175
# File 'lib/elastic_graph/support/config.rb', line 173

def with(**updates)
  (_ = self.class).new_without_validation(**to_h.merge(updates))
end