aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-04 22:07:07 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-13 00:01:57 +0100
commit8b8b7143efe2e0bac5bcfe90264e4baa66bdb532 (patch)
tree00da82fcb091b7de3c1e117d6d243231e3321773 /activemodel/lib/active_model
parent8d59e0b2633c26f9de8942a2d676afe39b0ee3f8 (diff)
downloadrails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.tar.gz
rails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.tar.bz2
rails-8b8b7143efe2e0bac5bcfe90264e4baa66bdb532.zip
Use an empty AttributeMethodMatcher by default.
This means that attribute methods which don't exist will get generated when define_attribute_methods is called, so we don't have to use hacks like `attribute_method_suffix ''`.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index bdc0eb4a0d..f058d3aa79 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -60,7 +60,7 @@ module ActiveModel
included do
class_attribute :attribute_method_matchers, :instance_writer => false
- self.attribute_method_matchers = []
+ self.attribute_method_matchers = [ClassMethods::AttributeMethodMatcher.new]
end
module ClassMethods
@@ -357,8 +357,11 @@ module ActiveModel
if attribute_method_matchers_cache.key?(method_name)
attribute_method_matchers_cache[method_name]
else
+ # Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix
+ # will match every time.
+ matchers = attribute_method_matchers.partition(&:plain?).reverse.flatten(1)
match = nil
- attribute_method_matchers.detect { |method| match = method.match(method_name) }
+ matchers.detect { |method| match = method.match(method_name) }
attribute_method_matchers_cache[method_name] = match
end
end
@@ -387,6 +390,10 @@ module ActiveModel
def method_name(attr_name)
@method_name % attr_name
end
+
+ def plain?
+ prefix.empty? && suffix.empty?
+ end
end
end