aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/boolean.rb
blob: 1311be3944faf06de9396aa4acd0fb14927ffd5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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(<<-EOM)
              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 sematics, and will cast to true in Rails 5.0. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to false.
            EOM
          end
          false
        end
      end
    end
  end
end