Fix structured error creation if attributes don't match; write match status to database

This commit is contained in:
Maximilian Grundke
2017-07-19 15:46:19 +02:00
parent 7ba245920c
commit 5d6158f95a
3 changed files with 17 additions and 3 deletions

View File

@ -3,7 +3,15 @@ class StructuredErrorAttribute < ActiveRecord::Base
belongs_to :error_template_attribute belongs_to :error_template_attribute
def self.create_from_template(attribute, structured_error, message_buffer) def self.create_from_template(attribute, structured_error, message_buffer)
value = message_buffer.match(attribute.regex).captures[0] match = false
self.create(structured_error: structured_error, error_template_attribute: attribute, value: value) value = nil
result = message_buffer.match(attribute.regex)
if result != nil
match = true
if result.captures.size > 0
value = result.captures[0]
end
end
self.create(structured_error: structured_error, error_template_attribute: attribute, value: value, match: match)
end end
end end

View File

@ -0,0 +1,5 @@
class AddMatchToStructuredErrorAttribute < ActiveRecord::Migration
def change
add_column :structured_error_attributes, :match, :boolean
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170711170928) do ActiveRecord::Schema.define(version: 20170719133351) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20170711170928) do
t.string "value" t.string "value"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "match"
end end
create_table "structured_errors", force: :cascade do |t| create_table "structured_errors", force: :cascade do |t|