aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/boolean.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type/boolean.rb')
-rw-r--r--activerecord/lib/active_record/type/boolean.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb
new file mode 100644
index 0000000000..978d16d524
--- /dev/null
+++ b/activerecord/lib/active_record/type/boolean.rb
@@ -0,0 +1,30 @@
+module ActiveRecord
+ module Type
+ class Boolean < Value # :nodoc:
+ def type
+ :boolean
+ end
+
+ private
+
+ def cast_value(value)
+ if value == ''
+ nil
+ elsif ConnectionAdapters::Column::TRUE_VALUES.include?(value)
+ true
+ else
+ if !ConnectionAdapters::Column::FALSE_VALUES.include?(value)
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ You attempted to assign a value which is not explicitly `true` or `false`
+ to a boolean column. Currently this value casts to `false`. This will
+ change to match Ruby's semantics, and will cast to `true` in Rails 5.
+ If you would like to maintain the current behavior, you should
+ explicitly handle the values you would like cast to `false`.
+ MSG
+ end
+ false
+ end
+ end
+ end
+ end
+end