Class: GovukSchemas::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_schemas/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#payloadObject

Returns the value of attribute payload.



4
5
6
# File 'lib/govuk_schemas/validator.rb', line 4

def payload
  @payload
end

#schema_nameObject (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

#typeObject (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_messageObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/govuk_schemas/validator.rb', line 16

def error_message
  "    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

Returns:

  • (Boolean)


12
13
14
# File 'lib/govuk_schemas/validator.rb', line 12

def valid?
  errors.empty?
end