diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 2 |
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) |