提交 cdf0f1aa 编写于 作者: J Jeremy Kemper

Faster and clearer value_to_boolean

上级 269c6c6b
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 @@ def string_to_dummy_time(string)
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册