Class: RequestHandler::Validation::DefinitionEngine
- Defined in:
- lib/request_handler/validation/definition_engine.rb
Class Method Summary collapse
- .error_message(validation_error) ⇒ Object
- .error_pointer(validation_error) ⇒ Object
- .valid_schema?(definition) ⇒ Boolean
-
.validate(value, schema, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- .validate!(value, schema, options: {}) ⇒ Object
Class Method Details
.error_message(validation_error) ⇒ Object
28 29 30 |
# File 'lib/request_handler/validation/definition_engine.rb', line 28 def self.(validation_error) validation_error.translated_error end |
.error_pointer(validation_error) ⇒ Object
32 33 34 |
# File 'lib/request_handler/validation/definition_engine.rb', line 32 def self.error_pointer(validation_error) validation_error.error_path.join("/") end |
.valid_schema?(definition) ⇒ Boolean
11 12 13 |
# File 'lib/request_handler/validation/definition_engine.rb', line 11 def self.valid_schema?(definition) definition.is_a?(::Definition::Types::Base) end |
.validate(value, schema, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
15 16 17 18 19 |
# File 'lib/request_handler/validation/definition_engine.rb', line 15 def self.validate(value, schema, options: {}) # rubocop:disable Lint/UnusedMethodArgument value = value.deep_symbolize_keys if value.is_a?(Hash) result = schema.conform(value) Result.new(output: result.value, errors: result.error_hash) end |
.validate!(value, schema, options: {}) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/request_handler/validation/definition_engine.rb', line 21 def self.validate!(value, schema, options: {}) validate(value, schema, options: ).tap do |result| valid = result.respond_to?(:valid?) ? result.valid? : result.success? raise Validation::Error unless valid end end |