Class: Arel::Attributes::Boolean

Inherits:
Arel::Attribute show all
Defined in:
lib/arel/algebra/attributes/boolean.rb

Instance Method Summary collapse

Methods inherited from Arel::Attribute

#aggregation?, #column, #eval, #format, #initialize, #inspect, #named?, #to_sql

Methods included from Arel::Attribute::Types

#type_cast_to_numeric, #typecast_error

Methods included from Arel::Attribute::Orderings

#asc, #desc

Methods included from Arel::Attribute::Expressions

#average, #count, #maximum, #minimum, #sum

Methods included from Arel::Attribute::Predications

#eq, #eq_all, #eq_any, #gt, #gt_all, #gt_any, #gteq, #gteq_all, #gteq_any, #in, #in_all, #in_any, #lt, #lt_all, #lt_any, #lteq, #lteq_all, #lteq_any, #matches, #matches_all, #matches_any, #not_eq, #not_eq_all, #not_eq_any, #not_in, #not_in_all, #not_in_any, #not_matches, #not_matches_all, #not_matches_any

Methods included from Arel::Attribute::Congruence

#/, #descends_from?, #find_correlate_in, #history, #join?, #original_attribute, #original_relation, #root

Methods included from Arel::Attribute::Transformations

#as, #bind, #hash, included, #to_attribute

Constructor Details

This class inherits a constructor from Arel::Attribute

Instance Method Details

#type_cast(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/arel/algebra/attributes/boolean.rb', line 4

def type_cast(value)
  case value
  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
    else         raise typecast_error(value)
    end
  end
end