aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-02 13:23:31 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-02 13:23:31 +0000
commit9acb340e88ac8a73ea410228e46457c3276fb1b4 (patch)
treeb124786a43b8792e8293361b841181ce729b7791 /activerecord/lib/active_record/attribute_methods
parent0306f82e0c3cda3aad1b45eb0c3a359c254b62cc (diff)
downloadrails-9acb340e88ac8a73ea410228e46457c3276fb1b4.tar.gz
rails-9acb340e88ac8a73ea410228e46457c3276fb1b4.tar.bz2
rails-9acb340e88ac8a73ea410228e46457c3276fb1b4.zip
Revert "Roflscaling!" (for now)
This reverts commit f6b5046305d43c5f64bcb6fed0e44f7bca99a603. Fear not, the roflscale will return when I have a bit more time and figure out a better way to do it. (In particular, a way that doesn't break the build.)
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb4
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb15
2 files changed, 11 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 7fbb459c34..c756924186 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -31,9 +31,9 @@ module ActiveRecord
if attr_name == primary_key && attr_name != 'id'
generated_attribute_methods.send(:alias_method, :id, primary_key)
generated_attribute_methods.module_eval <<-CODE, __FILE__, __LINE__
- def self.id(v, attributes, attributes_cache, attr_name)
+ def self.attribute_id(v, attributes, attributes_cache, attr_name)
attr_name = '#{primary_key}'
- send(attr_name, attributes[attr_name], attributes, attributes_cache, attr_name)
+ send(:'attribute_#{attr_name}', attributes[attr_name], attributes, attributes_cache, attr_name)
end
CODE
end
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 769aa36e79..8942fab500 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -30,9 +30,11 @@ module ActiveRecord
end
def undefine_attribute_methods
- if base_class == self && attribute_methods_generated?
- column_names.each do |name|
- generated_attribute_methods.singleton_class.send(:undef_method, name)
+ if base_class == self
+ generated_attribute_methods.module_eval do
+ public_methods(false).each do |m|
+ singleton_class.send(:undef_method, m) if m.to_s =~ /^attribute_/
+ end
end
end
@@ -65,7 +67,7 @@ module ActiveRecord
def __temp__(v, attributes, attributes_cache, attr_name)
#{external}
end
- alias_method '#{attr_name}', :__temp__
+ alias_method 'attribute_#{attr_name}', :__temp__
undef_method :__temp__
STR
end
@@ -108,11 +110,12 @@ module ActiveRecord
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
attr_name = attr_name.to_s
+ accessor = "attribute_#{attr_name}"
methods = self.class.generated_attribute_methods
- if methods.respond_to?(attr_name)
+ if methods.respond_to?(accessor)
if @attributes.has_key?(attr_name) || attr_name == 'id'
- methods.send(attr_name, @attributes[attr_name], @attributes, @attributes_cache, attr_name)
+ methods.send(accessor, @attributes[attr_name], @attributes, @attributes_cache, attr_name)
end
elsif !self.class.attribute_methods_generated?
# If we haven't generated the caster methods yet, do that and