Reuse ActiveRecord object after creating StructuredErrorAttributes
With these changes, the newly created StructuredError will have all StructuredErrorAttributes preloaded, thus speeding up further access to this association.
This commit is contained in:
@ -4,13 +4,12 @@ class StructuredErrorAttribute < ApplicationRecord
|
||||
belongs_to :structured_error
|
||||
belongs_to :error_template_attribute
|
||||
|
||||
def self.create_from_template(attribute, structured_error, message_buffer)
|
||||
def self.create_from_template(attribute, message_buffer)
|
||||
value = nil
|
||||
result = message_buffer.match(attribute.regex)
|
||||
if !result.nil? && result.captures.size.positive?
|
||||
value = result.captures[0]
|
||||
end
|
||||
create(structured_error:, error_template_attribute: attribute, value:,
|
||||
match: !result.nil?)
|
||||
create(error_template_attribute: attribute, value:, match: !result.nil?)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user