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.



5
6
7
8
9
# File 'lib/govuk_schemas/validator.rb', line 5

def initialize(schema_name, type, payload)
  @schema_name = schema_name
  @type = type
  @payload = payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



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

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



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

def error_message
  <<~DOC
    expected the payload to be valid against the '#{schema_name}' schema:

    #{formatted_payload}

    Validation errors:
    #{errors}
  DOC
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.empty?
end