Class: ActiveModel::Type::Integer
- Inherits:
-
Value
- Object
- Value
- ActiveModel::Type::Integer
- Includes:
- Helpers::Numeric
- Defined in:
- lib/active_model/type/integer.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_LIMIT =
8
Instance Method Summary collapse
- #deserialize(value) ⇒ Object
-
#initialize ⇒ Integer
constructor
A new instance of Integer.
- #serialize(value) ⇒ Object
- #type ⇒ Object
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 |