ManageIQ/manageiq

View on GitHub
app/models/widget_import_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class WidgetImportValidator
  class InvalidWidgetYamlError < StandardError; end
  class NonYamlError < StandardError; end

  def determine_validity(import_file_upload)
    widgets = YAML.load(import_file_upload.uploaded_content)

    raise InvalidWidgetYamlError unless widgets.all? do |widget_or_key, _|
      widget_or_key["MiqWidget"] || widget_or_key == "MiqWidget"
    end
  rescue Psych::SyntaxError
    raise NonYamlError
  rescue
    raise InvalidWidgetYamlError
  end
end