Class: GovukSchemas::Validator
- Inherits:
-
Object
- Object
- GovukSchemas::Validator
- Defined in:
- lib/govuk_schemas/validator.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#schema_name ⇒ Object
readonly
Returns the value of attribute schema_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(schema_name, type, payload) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(schema_name, type, payload) ⇒ Validator
Returns a new instance of Validator.
6 7 8 9 10 |
# File 'lib/govuk_schemas/validator.rb', line 6 def initialize(schema_name, type, payload) @schema_name = schema_name @type = type @payload = ensure_json(payload) end |
Instance Attribute Details
#payload ⇒ Object
Returns the value of attribute payload.
4 5 6 |
# File 'lib/govuk_schemas/validator.rb', line 4 def payload @payload end |
#schema_name ⇒ Object (readonly)
Returns the value of attribute schema_name.
3 4 5 |
# File 'lib/govuk_schemas/validator.rb', line 3 def schema_name @schema_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/govuk_schemas/validator.rb', line 3 def type @type end |
Instance Method Details
#error_message ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/govuk_schemas/validator.rb', line 16 def " expected the payload to be valid against the '\#{schema_name}' schema:\n\n \#{formatted_payload}\n\n Validation errors:\n \#{errors}\n DOC\nend\n" |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/govuk_schemas/validator.rb', line 12 def valid? errors.empty? end |