aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorChris Salzberg <chris@dejimata.com>2019-04-23 14:22:50 +0900
committerChris Salzberg <chris@dejimata.com>2019-04-23 14:24:40 +0900
commit14ff93c4bcb2a3da1fed917d5436d6605860936b (patch)
tree05b22a4eecf70c5a9c78f3dac558d9e411a269ce /activemodel
parentafc17e5ea21759df5b9ef2ac9421b02154a09b9b (diff)
downloadrails-14ff93c4bcb2a3da1fed917d5436d6605860936b.tar.gz
rails-14ff93c4bcb2a3da1fed917d5436d6605860936b.tar.bz2
rails-14ff93c4bcb2a3da1fed917d5436d6605860936b.zip
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
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 0075cd3c01..415f1f679b 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -352,8 +352,9 @@ module ActiveModel
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