Class: ActiveModel::Type::Integer
- Includes:
- Helpers::Numeric
- Defined in:
- activemodel/lib/active_model/type/integer.rb
Overview
:nodoc:
Direct Known Subclasses
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
Instance Method Summary collapse
- #deserialize(value) ⇒ Object
-
#initialize ⇒ Integer
constructor
A new instance of Integer.
- #serialize(value) ⇒ Object
- #type ⇒ Object
Methods included from Helpers::Numeric
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
#initialize ⇒ Integer
Returns a new instance of Integer.
12 13 14 15 |
# File 'activemodel/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 'activemodel/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 'activemodel/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 |
#type ⇒ Object
17 18 19 |
# File 'activemodel/lib/active_model/type/integer.rb', line 17 def type :integer end |