Class: ActiveModel::Type::Integer

Inherits:
Value show all
Includes:
Helpers::Numeric
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/integer.rb

Overview

:nodoc:

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

#limit, #precision, #scale

Instance Method Summary collapse

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

#initializeInteger

Returns a new instance of Integer.



12
13
14
15
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/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 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/integer.rb', line 21

def deserialize(value)
  return if value.blank?
  value.to_i
end

#serializable?(value) ⇒ Boolean

Returns:



31
32
33
34
35
36
37
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/integer.rb', line 31

def serializable?(value)
  cast_value = cast(value)
  in_range?(cast_value) || begin
    yield cast_value if block_given?
    false
  end
end

#serialize(value) ⇒ Object



26
27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/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

#typeObject



17
18
19
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/integer.rb', line 17

def type
  :integer
end