From 5d6158f95a2d63062fcdf89e20eec619316fd457 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 19 Jul 2017 15:46:19 +0200 Subject: [PATCH] Fix structured error creation if attributes don't match; write match status to database --- app/models/structured_error_attribute.rb | 12 ++++++++++-- ...133351_add_match_to_structured_error_attribute.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20170719133351_add_match_to_structured_error_attribute.rb diff --git a/app/models/structured_error_attribute.rb b/app/models/structured_error_attribute.rb index b9967719..6eb17fc4 100644 --- a/app/models/structured_error_attribute.rb +++ b/app/models/structured_error_attribute.rb @@ -3,7 +3,15 @@ class StructuredErrorAttribute < ActiveRecord::Base 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) + match = false + 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 diff --git a/db/migrate/20170719133351_add_match_to_structured_error_attribute.rb b/db/migrate/20170719133351_add_match_to_structured_error_attribute.rb new file mode 100644 index 00000000..7ec3ccc0 --- /dev/null +++ b/db/migrate/20170719133351_add_match_to_structured_error_attribute.rb @@ -0,0 +1,5 @@ +class AddMatchToStructuredErrorAttribute < ActiveRecord::Migration + def change + add_column :structured_error_attributes, :match, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 137d251d..62a776f9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20170711170928) do t.string "value" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "match" end create_table "structured_errors", force: :cascade do |t|