Class: PublishingPlatformSchemas::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/publishing_platform_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.



8
9
10
11
12
# File 'lib/publishing_platform_schemas/validator.rb', line 8

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.



6
7
8
# File 'lib/publishing_platform_schemas/validator.rb', line 6

def payload
  @payload
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



5
6
7
# File 'lib/publishing_platform_schemas/validator.rb', line 5

def schema_name
  @schema_name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/publishing_platform_schemas/validator.rb', line 5

def type
  @type
end

Instance Method Details

#error_messageObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/publishing_platform_schemas/validator.rb', line 18

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)


14
15
16
# File 'lib/publishing_platform_schemas/validator.rb', line 14

def valid?
  errors.empty?
end