Class: GovukContentSchemaTestHelpers::Validator
- Inherits:
-
Object
- Object
- GovukContentSchemaTestHelpers::Validator
- Defined in:
- lib/govuk-content-schema-test-helpers/validator.rb
Class Method Summary collapse
-
.schema_path(schema_name) ⇒ Object
Return the first schema path that exists on the filesystem.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(schema_name, document) ⇒ Validator
constructor
schema_name should be a string, such as ‘finder’ document should be a JSON string of the document to validate.
- #valid? ⇒ Boolean
Constructor Details
#initialize(schema_name, document) ⇒ Validator
schema_name should be a string, such as ‘finder’ document should be a JSON string of the document to validate
14 15 16 17 18 |
# File 'lib/govuk-content-schema-test-helpers/validator.rb', line 14 def initialize(schema_name, document) Util.check_govuk_content_schemas_path! @schema_path = GovukContentSchemaTestHelpers::Validator.schema_path(schema_name) @document = document end |
Class Method Details
.schema_path(schema_name) ⇒ Object
Return the first schema path that exists on the filesystem
6 7 8 9 10 |
# File 'lib/govuk-content-schema-test-helpers/validator.rb', line 6 def self.schema_path(schema_name) paths = candidate_schema_paths(schema_name) paths.detect { |path| File.exists?(path) } || raise(ImproperlyConfiguredError, "Schema file not found at any of: #{paths.join(', ')}.") end |
Instance Method Details
#errors ⇒ Object
24 25 26 |
# File 'lib/govuk-content-schema-test-helpers/validator.rb', line 24 def errors @errors ||= JSON::Validator.fully_validate(@schema_path, @document) end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/govuk-content-schema-test-helpers/validator.rb', line 20 def valid? errors.empty? end |