Module: Hyrax::Workflow::WorkflowImporter::SchemaValidator

Defined in:
app/services/hyrax/workflow/workflow_importer.rb

Class Method Summary collapse

Class Method Details

.call(data:, schema:, logger:) ⇒ Boolean

Returns true if the data validates from the schema.

Parameters:

  • data (Hash)
  • schema (#call)

Returns:

  • (Boolean)

    true if the data validates from the schema

Raises:

  • (RuntimeError)

    if the data does not validate against the schema



169
170
171
172
173
174
175
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 169

def self.call(data:, schema:, logger:)
  result = schema.call(data)
  return true if result.success?
  message = format_message(result)
  logger.error(message)
  raise message
end

.format_message(result) ⇒ String

Parameters:

  • result (Dry::Validation::Result)

Returns:

  • (String)


181
182
183
184
185
186
187
188
# File 'app/services/hyrax/workflow/workflow_importer.rb', line 181

def self.format_message(result)
  messages = result.errors(full: true).map do |msg|
    "Error on workflow entry #{msg.path}\n\t#{msg.text}\n\tGot: #{msg.input || '[no entry]'}"
  end

  messages << "Input was:\n\t#{result.to_h}"
  messages.join("\n")
end