Update comment in attribute_method_matchers_matching

The current comment here is from 2011 and its original context has
changed completely. The plain matcher will not "match every time"
anymore since the code now filters all matchers, and only selects those
for which the captured attribute is valid.

To avoid confusion, I updated the comment. For more discussion, see:

https://github.com/rails/rails/pull/36005
This commit is contained in:
Chris Salzberg 2019-04-23 14:22:50 +09:00
parent afc17e5ea2
commit 14ff93c4bc
No known key found for this signature in database
GPG Key ID: C0C7B09832CB1CB1

@ -352,8 +352,9 @@ def attribute_method_matchers_cache
def attribute_method_matchers_matching(method_name)
attribute_method_matchers_cache.compute_if_absent(method_name) do
# Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix
# will match every time.
# 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
end