Class: ActiveModel::Type::Integer

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

Overview

:nodoc:

Direct Known Subclasses

BigInteger

Constant Summary collapse

DEFAULT_LIMIT =

Column storage size in bytes. 4 bytes means an 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?, #force_equality?, #hash, #map, #type_cast_for_schema, #value_constructed_by_mass_assignment?

Constructor Details

#initializeInteger

Returns a new instance of Integer.



12
13
14
15
# File 'lib/active_model/type/integer.rb', line 12

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

Instance Method Details

#deserialize(value) ⇒ Object



21
22
23
24
# File 'lib/active_model/type/integer.rb', line 21

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

#serialize(value) ⇒ Object



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

def serialize(value)
  return if value.is_a?(::String) && non_numeric_string?(value)
  ensure_in_range(super)
end

#typeObject



17
18
19
# File 'lib/active_model/type/integer.rb', line 17

def type
  :integer
end