aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-03-28 14:44:34 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-03-28 14:44:34 +1100
commit2bcc2ebf44b59e46c104c92d621e8051c97bfcf5 (patch)
treed2a3f04fd3020c1b5d88847af62d52f2d5e5bd61 /activemodel/lib/active_model/attribute_methods.rb
parentf5774e3e3f70a3acfa559b9ff889e9417fb71d4b (diff)
parent8398f21880a952769ccd6437a4344922fe596dab (diff)
downloadrails-2bcc2ebf44b59e46c104c92d621e8051c97bfcf5.tar.gz
rails-2bcc2ebf44b59e46c104c92d621e8051c97bfcf5.tar.bz2
rails-2bcc2ebf44b59e46c104c92d621e8051c97bfcf5.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/lib/active_model/attribute_methods.rb')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 588976f1d4..f04829ef09 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -53,7 +53,6 @@ module ActiveModel
module AttributeMethods
extend ActiveSupport::Concern
- # Declare and check for suffixed attribute methods.
module ClassMethods
# Defines an "attribute" method (like +inheritance_column+ or
# +table_name+). A new (class) method will be created with the
@@ -90,13 +89,20 @@ module ActiveModel
# # => 'address_id'
def define_attr_method(name, value=nil, &block)
sing = singleton_class
- sing.send :alias_method, "original_#{name}", name
+ sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
+ if method_defined?(:original_#{name})
+ undef :original_#{name}
+ end
+ alias_method :original_#{name}, :#{name}
+ eorb
if block_given?
sing.send :define_method, name, &block
else
# use eval instead of a block to work around a memory leak in dev
# mode in fcgi
- sing.class_eval "def #{name}; #{value.to_s.inspect}; end"
+ sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
+ def #{name}; #{value.to_s.inspect}; end
+ eorb
end
end
@@ -257,8 +263,13 @@ module ActiveModel
if respond_to?(generate_method)
send(generate_method, attr_name)
else
+ method_name = matcher.method_name(attr_name)
+
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__+1
- def #{matcher.method_name(attr_name)}(*args)
+ if method_defined?(:#{method_name})
+ undef :#{method_name}
+ end
+ def #{method_name}(*args)
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)
end
STR
@@ -286,6 +297,7 @@ module ActiveModel
end
end
+ # Returns true if the attribute methods defined have been generated.
def attribute_methods_generated?
@attribute_methods_generated ||= nil
end