Class: Hyrax::FlexibleSchemaValidatorService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/flexible_schema_validator_service.rb

Constant Summary collapse

DEFAULT_SCHEMA =
Hyrax::Engine.root.join('config', 'metadata_profiles', 'm3_json_schema.json')
REQUIRED_CLASSES =
[
  Hyrax.config.admin_set_model,
  Hyrax.config.collection_model,
  Hyrax.config.file_set_model
].map { |str| str.gsub(/^::/, '') }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile:, schema: default_schema) ⇒ void

Initializes a new FlexibleSchemaValidatorService.

Parameters:

  • profile (Hash)

    the flexible metadata profile to validate

  • schema (Pathname, String) (defaults to: default_schema)

    the JSON schema to validate against. Defaults to DEFAULT_SCHEMA.



20
21
22
23
24
25
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 20

def initialize(profile:, schema: default_schema)
  @profile = profile
  @schema = schema
  @schemer = JSONSchemer.schema(schema)
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



12
13
14
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 12

def errors
  @errors
end

#profileObject (readonly)

Returns the value of attribute profile.



12
13
14
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 12

def profile
  @profile
end

#schemaObject (readonly)

Returns the value of attribute schema.



12
13
14
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 12

def schema
  @schema
end

#schemerObject (readonly)

Returns the value of attribute schemer.



12
13
14
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 12

def schemer
  @schemer
end

Instance Method Details

#default_schemaPathname

The default JSON schema used when no custom schema is provided.

Returns:

  • (Pathname)


44
45
46
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 44

def default_schema
  DEFAULT_SCHEMA
end

#required_classesArray<String>

Classes that MUST be present in every flexible metadata profile.

Returns:

  • (Array<String>)


51
52
53
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 51

def required_classes
  REQUIRED_CLASSES
end

#validate!void

This method returns an undefined value.

Execute all validation routines and populate #errors with any issues discovered.



31
32
33
34
35
36
37
38
39
# File 'app/services/hyrax/flexible_schema_validator_service.rb', line 31

def validate!
  validate_required_classes
  validate_class_availability
  validate_available_on_classes_defined
  validate_existing_records_classes_defined
  validate_schema
  validate_label_prop
  
end