aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/attributes/boolean.rb
blob: 0ca7cd6d246903369d99cb70927a9a335b490a35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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