aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/attributes/boolean.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/attributes/boolean.rb')
-rw-r--r--lib/arel/algebra/attributes/boolean.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/arel/algebra/attributes/boolean.rb b/lib/arel/algebra/attributes/boolean.rb
new file mode 100644
index 0000000000..0ca7cd6d24
--- /dev/null
+++ b/lib/arel/algebra/attributes/boolean.rb
@@ -0,0 +1,20 @@
+module Arel
+ module Attributes
+ 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
+ case value.to_s.downcase.strip
+ when 'true' then true
+ when 'false' then false
+ else raise typecast_error(value)
+ end
+ end
+ end
+ end
+ end
+end