Class: ActiveModel::Type::Integer

Inherits:
Value show all
Includes:
Helpers::Numeric
Defined in:
activemodel/lib/active_model/type/integer.rb

Overview

:nodoc:

Direct Known Subclasses

BigInteger, UnsignedInteger

Constant Summary collapse

DEFAULT_LIMIT =

Column storage size in bytes. 4 bytes means a MySQL int or Postgres integer as opposed to smallint etc.

4

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Helpers::Numeric

#cast, #changed?

Methods inherited from Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #hash, #map, #type_cast_for_schema

Constructor Details

#initializeInteger

Returns a new instance of Integer.


10
11
12
13
# File 'activemodel/lib/active_model/type/integer.rb', line 10

def initialize(*)
  super
  @range = min_value...max_value
end

Instance Method Details

#deserialize(value) ⇒ Object


19
20
21
22
# File 'activemodel/lib/active_model/type/integer.rb', line 19

def deserialize(value)
  return if value.nil?
  value.to_i
end

#serialize(value) ⇒ Object


24
25
26
27
28
29
30
# File 'activemodel/lib/active_model/type/integer.rb', line 24

def serialize(value)
  result = cast(value)
  if result
    ensure_in_range(result)
  end
  result
end

#typeObject


15
16
17
# File 'activemodel/lib/active_model/type/integer.rb', line 15

def type
  :integer
end