Skip to content

Commit

Permalink
Avoid creating multiple regexp objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlosantoniodasilva committed May 24, 2024
1 parent ae12516 commit e451998
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e451998

Please sign in to comment.