From 391f978acdf9b4789f9ac301a72b99e05ace64f1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 10 Aug 2009 11:58:44 -0500 Subject: [PATCH] AMo overrides alias_attribute and manages aliasing all known attribute method matchers --- .../lib/active_model/attribute_methods.rb | 10 ++++++++++ .../active_record/attribute_methods/dirty.rb | 17 ----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 1ae042e00f..1091ad3095 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -133,6 +133,16 @@ module ActiveModel undefine_attribute_methods end + def alias_attribute(new_name, old_name) + attribute_method_matchers.each do |matcher| + module_eval <<-STR, __FILE__, __LINE__+1 + def #{matcher.method_name(new_name)}(*args) + send(:#{matcher.method_name(old_name)}, *args) + end + STR + end + end + def define_attribute_methods(attr_names) return if attribute_methods_generated? attr_names.each do |attr_name| diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 911c908c8b..37a46f7d88 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -182,23 +182,6 @@ module ActiveRecord old != value end - - module ClassMethods - def self.extended(base) - class << base - alias_method_chain :alias_attribute, :dirty - end - end - - def alias_attribute_with_dirty(new_name, old_name) - alias_attribute_without_dirty(new_name, old_name) - DIRTY_AFFIXES.each do |affixes| - module_eval <<-STR, __FILE__, __LINE__+1 - def #{affixes[:prefix]}#{new_name}#{affixes[:suffix]}; self.#{affixes[:prefix]}#{old_name}#{affixes[:suffix]}; end # def reset_subject!; self.reset_title!; end - STR - end - end - end end end end