From ba02a8b62015359abbed26ce7931116cb5c56c8f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 14 May 2024 18:53:28 -0300 Subject: [PATCH] Avoid creating multiple regexp objects The check is slightly different but should work for our purposes here. Using `end_with?(mapping)` to keep a similar check doesn't work because some Ruby versions include "did you mean", which make the error message look something like this: NameError: uninitialized constant StringInput at.const_get(mapping) ^^^^^^^^^^ Did you mean? StringInputTest The regexp check worked because it was matching the end of the line, not end of string, with `$`, so it'd match the first line of the error message always. --- CHANGELOG.md | 1 + lib/simple_form/form_builder.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ec3c81..90de8c71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased * Revert "Speed up input mapping lookup by avoiding rescuing exceptions" from v5.3.0, it caused a regression on dev/test environments with custom inputs. +* Try a slightly different approach to input lookups, without relying on regexp, to see if that helps with performance as originally intended. * Add support to Ruby 3.3. (no changes required.) ## 5.3.0 diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index da723cb7..d7cf621b 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -676,7 +676,7 @@ def attempt_mapping(mapping, at) begin at.const_get(mapping) rescue NameError => e - raise if e.message !~ /#{mapping}$/ + raise unless e.message.include?(mapping) end end