Class: ActiveRecord::Type::Integer

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Numeric

#changed?, #number?, #type_cast

Methods inherited from Value

#==, #binary?, #changed?, #changed_in_place?, #hash, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_user

Constructor Details

#initializeInteger

Returns a new instance of Integer.



6
7
8
9
# File 'lib/active_record/type/integer.rb', line 6

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

Instance Method Details

#typeObject



11
12
13
# File 'lib/active_record/type/integer.rb', line 11

def type
  :integer
end

#type_cast_for_database(value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/active_record/type/integer.rb', line 20

def type_cast_for_database(value)
  result = type_cast(value)
  if result
    ensure_in_range(result)
  end
  result
end

#type_cast_from_database(value) ⇒ Object



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

def type_cast_from_database(value)
  return if value.nil?
  value.to_i
end