aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/algebra/attributes/attribute.rb13
-rw-r--r--lib/arel/algebra/attributes/boolean.rb11
2 files changed, 11 insertions, 13 deletions
diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb
index f4cec828e3..03cf44a552 100644
--- a/lib/arel/algebra/attributes/attribute.rb
+++ b/lib/arel/algebra/attributes/attribute.rb
@@ -160,16 +160,13 @@ module Arel
def type_cast_to_numeric(value, method)
return unless value
if value.respond_to?(:to_str)
- if value.to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
- $1.send(method)
- else
- value
- end
+ str = value.to_str.strip
+ return if str.empty?
+ return $1.send(method) if str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
elsif value.respond_to?(method)
- value.send(method)
- else
- raise typecast_error(value)
+ return value.send(method)
end
+ raise typecast_error(value)
end
def typecast_error(value)
diff --git a/lib/arel/algebra/attributes/boolean.rb b/lib/arel/algebra/attributes/boolean.rb
index 0ca7cd6d24..d69f2465df 100644
--- a/lib/arel/algebra/attributes/boolean.rb
+++ b/lib/arel/algebra/attributes/boolean.rb
@@ -3,11 +3,12 @@ module Arel
class Boolean < Attribute
def type_cast(value)
case value
- when true, false then value
- when nil then options[:allow_nil] ? nil : false
- when 1 then true
- when 0 then false
- else
+ when true, false then value
+ # when nil then options[:allow_nil] ? nil : false
+ when nil then false
+ when 1 then true
+ when 0 then false
+ else
case value.to_s.downcase.strip
when 'true' then true
when 'false' then false