aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:32:33 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:32:33 -0700
commit59482f93ec84a54069ef720ed4ecf5c4a3d302a0 (patch)
treee5ffff61947b99dffb077d582c0f6397b0bde3b1 /activerecord
parent6aea51355ae221a422e8501b585619895cded8f4 (diff)
downloadrails-59482f93ec84a54069ef720ed4ecf5c4a3d302a0.tar.gz
rails-59482f93ec84a54069ef720ed4ecf5c4a3d302a0.tar.bz2
rails-59482f93ec84a54069ef720ed4ecf5c4a3d302a0.zip
stop storing multiple copies of a particular attribute name
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb22
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb5
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb5
3 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 9f8f309c02..13d7c6b781 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -19,6 +19,15 @@ module ActiveRecord
include Serialization
end
+ AttrNames = Module.new {
+ def self.set_name_cache(name, value)
+ const_name = "ATTR_#{name}"
+ unless const_defined? const_name
+ const_set const_name, value
+ end
+ end
+ }
+
module ClassMethods
def inherited(child_class) #:nodoc:
child_class.initialize_generated_modules
@@ -26,18 +35,7 @@ module ActiveRecord
end
def initialize_generated_modules # :nodoc:
- @generated_attribute_methods = Module.new {
- extend Mutex_m
-
- const_set :AttrNames, Module.new {
- def self.set_name_cache(name, value)
- const_name = "ATTR_#{name}"
- unless const_defined? const_name
- const_set const_name, value
- end
- end
- }
- }
+ @generated_attribute_methods = Module.new { extend Mutex_m }
@attribute_methods_generated = false
include @generated_attribute_methods
end
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index d83c5a84b4..2c8ae9c774 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -49,11 +49,12 @@ module ActiveRecord
# key the @attributes_cache in read_attribute.
def define_method_attribute(name)
safe_name = name.unpack('h*').first
- generated_attribute_methods::AttrNames.set_name_cache safe_name, name
+ ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__#{safe_name}
- read_attribute(AttrNames::ATTR_#{safe_name}) { |n| missing_attribute(n, caller) }
+ name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
+ read_attribute(name) { |n| missing_attribute(n, caller) }
end
alias_method #{name.inspect}, :__temp__#{safe_name}
undef_method :__temp__#{safe_name}
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index 541856c678..9c7f643283 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -14,11 +14,12 @@ module ActiveRecord
# this code.
def define_method_attribute=(name)
safe_name = name.unpack('h*').first
- generated_attribute_methods::AttrNames.set_name_cache safe_name, name
+ ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__#{safe_name}=(value)
- write_attribute(AttrNames::ATTR_#{safe_name}, value)
+ name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
+ write_attribute(name, value)
end
alias_method #{(name + '=').inspect}, :__temp__#{safe_name}=
undef_method :__temp__#{safe_name}=