diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-03-27 00:21:25 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-03-27 00:21:25 +0530 |
commit | 2fc32636dc07cd4986e065be2ab3fbded34cbe18 (patch) | |
tree | 7ceb3541e30d5559b0f51093f27970485d505f7e /activemodel/lib/active_model | |
parent | 547407a9fb375601deb0834fb1c2d9a108c9aea1 (diff) | |
parent | 7c6807296b114f0688e6e74494f1d43d3a0548ba (diff) | |
download | rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.gz rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.tar.bz2 rails-2fc32636dc07cd4986e065be2ab3fbded34cbe18.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 13 | ||||
-rw-r--r-- | activemodel/lib/active_model/lint.rb | 4 |
2 files changed, 10 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 2a99450a3d..be55581c66 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -106,11 +106,14 @@ module ActiveModel 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 <<-eorb, __FILE__, __LINE__ + 1 - def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end - eorb + if name =~ /^[a-zA-Z_]\w*[!?=]?$/ + sing.class_eval <<-eorb, __FILE__, __LINE__ + 1 + def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end + eorb + else + value = value.to_s if value + sing.send(:define_method, name) { value } + end end end diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb index 957d1b9d70..b71ef4b22e 100644 --- a/activemodel/lib/active_model/lint.rb +++ b/activemodel/lib/active_model/lint.rb @@ -23,7 +23,7 @@ module ActiveModel def test_to_key assert model.respond_to?(:to_key), "The model should respond to to_key" def model.persisted?() false end - assert model.to_key.nil? + assert model.to_key.nil?, "to_key should return nil when `persisted?` returns false" end # == Responds to <tt>to_param</tt> @@ -40,7 +40,7 @@ module ActiveModel assert model.respond_to?(:to_param), "The model should respond to to_param" def model.to_key() [1] end def model.persisted?() false end - assert model.to_param.nil? + assert model.to_param.nil?, "to_param should return nil when `persisted?` returns false" end # == Responds to <tt>valid?</tt> |