Class: ActiveModel::Type::Integer

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

Overview

:nodoc:

Constant Summary collapse

DEFAULT_LIMIT =
8

Instance Method Summary collapse

Constructor Details

#initializeInteger

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

#typeObject



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

def type
  :integer
end