Module: ActiveRecord::Type::Numeric

Included in:
Decimal, Float, Integer
Defined in:
activerecord/lib/active_record/type/numeric.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#changed?(old_value, _new_value, new_value_before_type_cast) ⇒ Boolean

:nodoc:

Returns:


18
19
20
# File 'activerecord/lib/active_record/type/numeric.rb', line 18

def changed?(old_value, _new_value, new_value_before_type_cast) # :nodoc:
  super || number_to_non_number?(old_value, new_value_before_type_cast)
end

#number?Boolean

Returns:


4
5
6
# File 'activerecord/lib/active_record/type/numeric.rb', line 4

def number?
  true
end

#type_cast(value) ⇒ Object


8
9
10
11
12
13
14
15
16
# File 'activerecord/lib/active_record/type/numeric.rb', line 8

def type_cast(value)
  value = case value
          when true then 1
          when false then 0
          when ::String then value.presence
          else value
          end
  super(value)
end