Class: LightGptProxy::SchemaValidator
- Inherits:
-
Object
- Object
- LightGptProxy::SchemaValidator
- Defined in:
- lib/light_gpt_proxy/schema_validator.rb
Constant Summary collapse
- ValidationError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema) ⇒ SchemaValidator
constructor
A new instance of SchemaValidator.
- #validate!(payload) ⇒ Object (also: #[])
Constructor Details
#initialize(schema) ⇒ SchemaValidator
Returns a new instance of SchemaValidator.
9 10 11 |
# File 'lib/light_gpt_proxy/schema_validator.rb', line 9 def initialize(schema) @schema = schema end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/light_gpt_proxy/schema_validator.rb', line 7 def payload @payload end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
7 8 9 |
# File 'lib/light_gpt_proxy/schema_validator.rb', line 7 def schema @schema end |
Instance Method Details
#validate!(payload) ⇒ Object Also known as: []
13 14 15 16 17 18 19 |
# File 'lib/light_gpt_proxy/schema_validator.rb', line 13 def validate!(payload) @payload = payload errors = validate_schema(schema, payload) raise ValidationError, errors.join(', ') if errors.any? true end |