diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-28 17:39:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-28 17:39:38 -0800 |
commit | 72c18189410513bbf474cb9d678b14d2e3591cc5 (patch) | |
tree | e20c277d633088e4e9b6fc13b21e00afdd9550cd /activerecord/lib | |
parent | fa779c5357fd9396644ffc46e8ec575444f2f029 (diff) | |
download | rails-72c18189410513bbf474cb9d678b14d2e3591cc5.tar.gz rails-72c18189410513bbf474cb9d678b14d2e3591cc5.tar.bz2 rails-72c18189410513bbf474cb9d678b14d2e3591cc5.zip |
use an identity conversion to avoid conditional codes
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 660fa9a564..ff088200a1 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -60,8 +60,8 @@ module ActiveRecord # Define an attribute reader method. Cope with nil column. def define_read_method(symbol, attr_name, column) - cast_code = column.type_cast_code('v') if column - access_code = cast_code ? "(v=@attributes['#{attr_name}']) && #{cast_code}" : "@attributes['#{attr_name}']" + cast_code = column.type_cast_code('v') + access_code = "(v=@attributes['#{attr_name}']) && #{cast_code}" unless attr_name.to_s == self.primary_key.to_s access_code.insert(0, "missing_attribute('#{attr_name}', caller) unless @attributes.has_key?('#{attr_name}'); ") diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 60ccf9edf3..1a5d0c2f6d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -87,8 +87,8 @@ module ActiveRecord def type_cast_code(var_name) case type - when :string then nil - when :text then nil + when :string then var_name + when :text then var_name when :integer then "(#{var_name}.to_i rescue #{var_name} ? 1 : 0)" when :float then "#{var_name}.to_f" when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})" |