aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:19:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-02 17:19:21 -0700
commit6aea51355ae221a422e8501b585619895cded8f4 (patch)
treed4546cfc91d5d08f170efcb4774ca5d1b0501b95 /activerecord
parent8eb7561ac6e8f020ec09608532de310c6b0b8dcd (diff)
downloadrails-6aea51355ae221a422e8501b585619895cded8f4.tar.gz
rails-6aea51355ae221a422e8501b585619895cded8f4.tar.bz2
rails-6aea51355ae221a422e8501b585619895cded8f4.zip
eagerly assign the attribute name cache, remove const_missing
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb7
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb2
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb2
3 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 701fd4e3fa..9f8f309c02 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -30,8 +30,11 @@ module ActiveRecord
extend Mutex_m
const_set :AttrNames, Module.new {
- def self.const_missing(name)
- const_set(name, [name.to_s.sub(/ATTR_/, '')].pack('h*').freeze)
+ def self.set_name_cache(name, value)
+ const_name = "ATTR_#{name}"
+ unless const_defined? const_name
+ const_set const_name, value
+ end
end
}
}
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 506f5d75f9..d83c5a84b4 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -49,6 +49,8 @@ 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
+
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__#{safe_name}
read_attribute(AttrNames::ATTR_#{safe_name}) { |n| missing_attribute(n, caller) }
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index cd33494cc3..541856c678 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -14,6 +14,8 @@ 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
+
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__#{safe_name}=(value)
write_attribute(AttrNames::ATTR_#{safe_name}, value)