Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

eagerly assign the attribute name cache, remove const_missing

  • Loading branch information...
commit 532f89f77c14549d0bf631e45b77a9066d5bba7f 1 parent ec50c75
@tenderlove tenderlove authored
View
7 activerecord/lib/active_record/attribute_methods.rb
@@ -30,8 +30,11 @@ def initialize_generated_modules # :nodoc:
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
}
}
View
2  activerecord/lib/active_record/attribute_methods/read.rb
@@ -49,6 +49,8 @@ def cache_attribute?(attr_name)
# 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) }
View
2  activerecord/lib/active_record/attribute_methods/write.rb
@@ -14,6 +14,8 @@ module ClassMethods
# 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)
Please sign in to comment.
Something went wrong with that request. Please try again.