diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-12 11:42:17 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-14 11:41:56 -0700 |
commit | cdf0f1aa2ee4ba73bafc9b9217ee35b7f7eb3273 (patch) | |
tree | 9500b926a96894339a3b3d3f970f08351bb6f038 /activerecord | |
parent | 269c6c6bcfec342cf830e0b20c44bb2c888e8fdf (diff) | |
download | rails-cdf0f1aa2ee4ba73bafc9b9217ee35b7f7eb3273.tar.gz rails-cdf0f1aa2ee4ba73bafc9b9217ee35b7f7eb3273.tar.bz2 rails-cdf0f1aa2ee4ba73bafc9b9217ee35b7f7eb3273.zip |
Faster and clearer value_to_boolean
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 9 |
1 files changed, 4 insertions, 5 deletions
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 13ccfea0b8..31d6c7942c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -1,4 +1,5 @@ require 'date' +require 'set' require 'bigdecimal' require 'bigdecimal/util' @@ -6,6 +7,8 @@ module ActiveRecord module ConnectionAdapters #:nodoc: # An abstract definition of a column in a table. class Column + TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set + module Format ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/ ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ @@ -135,11 +138,7 @@ module ActiveRecord # convert something to a boolean def value_to_boolean(value) - if value == true || value == false - value - else - !(value.to_s !~ /\A(?:1|t|true)\Z/i) - end + TRUE_VALUES.include?(value) end # convert something to a BigDecimal |