diff options
author | Chris Salzberg <chris@dejimata.com> | 2019-04-17 21:08:11 +0900 |
---|---|---|
committer | Chris Salzberg <chris@dejimata.com> | 2019-05-31 12:55:59 +0900 |
commit | dd0357aeb85b6466dea97800c9f45cb6080f1324 (patch) | |
tree | 4c5820da03e35048ea6b7c906358d02ebeb817dc /activemodel | |
parent | 5ce1f66d7ac50492f4cd1e6bd0170b2c888ec73d (diff) | |
download | rails-dd0357aeb85b6466dea97800c9f45cb6080f1324.tar.gz rails-dd0357aeb85b6466dea97800c9f45cb6080f1324.tar.bz2 rails-dd0357aeb85b6466dea97800c9f45cb6080f1324.zip |
Make plain matcher match first, not last
This code takes the "plain" matcher with no prefix and suffix and puts
it at the end of the matchers array such that it is de-prioritized among
all matchers. The comment explaining this code, originally from commimt
8b8b7143efe dated in 2011, is in a context where detection from matchers
happened immediately. In that situation, the plain matcher would indeed
always match first and no others would ever be used.
However, the current code does not immediately detect one match but
rather maps matchers to matches for the method_name. Detection only
happens for matches whose attribute name is valid.
In this context, there is no need to bump the plain matcher to the end
of the array, since it will only be selected if the attribute name it
catpures matches a valid attribute name.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 415f1f679b..cbd7798543 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -352,11 +352,7 @@ module ActiveModel def attribute_method_matchers_matching(method_name) attribute_method_matchers_cache.compute_if_absent(method_name) do - # Bump plain matcher to last place so that only methods that do not - # match any other pattern match the actual attribute name. - # This is currently only needed to support legacy usage. - matchers = attribute_method_matchers.partition(&:plain?).reverse.flatten(1) - matchers.map { |matcher| matcher.match(method_name) }.compact + attribute_method_matchers.map { |matcher| matcher.match(method_name) }.compact end end |