Extract structured errors on run and submit

This commit is contained in:
Maximilian Grundke
2017-07-12 09:52:33 +02:00
parent 872611bff6
commit 4d684a7a05
4 changed files with 36 additions and 1 deletions

View File

@@ -1,4 +1,12 @@
class StructuredError < ActiveRecord::Base
belongs_to :error_template
belongs_to :file, class_name: 'CodeOcean::File'
def self.create_from_template(template, message_buffer)
instance = self.create(error_template: template)
template.error_template_attributes.each do |attribute|
StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer)
end
instance
end
end

View File

@@ -1,4 +1,9 @@
class StructuredErrorAttribute < ActiveRecord::Base
belongs_to :structured_error
belongs_to :error_template_attribute
def self.create_from_template(attribute, structured_error, message_buffer)
value = message_buffer.match(attribute.regex).captures[0]
self.create(structured_error: structured_error, error_template_attribute: attribute, value: value)
end
end