Class: ActiveModel::Type::Integer
- Includes:
- Helpers::Numeric
- Defined in:
- lib/active_model/type/integer.rb
Overview
:nodoc:
Direct Known Subclasses
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
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?, #hash, #map, #type_cast_for_schema
Constructor Details
#initialize ⇒ Integer
Returns a new instance of Integer.
10 11 12 13 |
# File '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 '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 'lib/active_model/type/integer.rb', line 24 def serialize(value) result = cast(value) if result ensure_in_range(result) end result end |
#type ⇒ Object
15 16 17 |
# File 'lib/active_model/type/integer.rb', line 15 def type :integer end |