class ActiveModel::Type::Integer

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/active_model/type/integer.rbs

class ActiveModel::Type::Integer < ActiveModel::Type::Value
  def _limit: () -> Integer
  def cast_value: ((Integer | String) value) -> Integer
  def deserialize: (Integer? value) -> Integer?
  def ensure_in_range: (Integer value) -> Integer
  def in_range?: (Integer? value) -> true
  def max_value: () -> Integer
  def min_value: () -> Integer
  def serializable?: ((Integer | String) value) -> true
  def serialize: ((Integer | nil | String) value) -> Integer?
  def type: () -> Symbol
end

:nodoc:

def _limit

Experimental RBS support (using type sampling data from the type_fusion project).

def _limit: () -> Integer

This signature was generated using 3 samples from 1 application.

def _limit
  limit || DEFAULT_LIMIT
end

def cast_value(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def cast_value: ((Integer | String) value) -> Integer

This signature was generated using 33 samples from 2 applications.

def cast_value(value)
  value.to_i rescue nil
end

def deserialize(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def deserialize: (Integer? value) -> Integer?

This signature was generated using 34 samples from 2 applications.

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

def ensure_in_range(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def ensure_in_range: (Integer value) -> Integer

This signature was generated using 16 samples from 2 applications.

def ensure_in_range(value)
  unless in_range?(value)
    raise ActiveModel::RangeError, "#{value} is out of range for #{self.class} with limit #{_limit} bytes"
  end
  value
end

def in_range?(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def in_range?: (Integer? value) -> true

This signature was generated using 20 samples from 2 applications.

def in_range?(value)
  !value || range.member?(value)
end

def initialize(**)

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

def max_value

Experimental RBS support (using type sampling data from the type_fusion project).

def max_value: () -> Integer

This signature was generated using 3 samples from 2 applications.

def max_value
  1 << (_limit * 8 - 1) # 8 bits per byte with one bit for sign
end

def min_value

Experimental RBS support (using type sampling data from the type_fusion project).

def min_value: () -> Integer

This signature was generated using 3 samples from 1 application.

def min_value
  -max_value
end

def serializable?(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def serializable?: ((Integer | String) value) -> true

This signature was generated using 4 samples from 1 application.

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

def serialize(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def serialize: ((Integer | nil | String) value) -> Integer?

This signature was generated using 39 samples from 2 applications.

def serialize(value)
  return if value.is_a?(::String) && non_numeric_string?(value)
  ensure_in_range(super)
end

def type

Experimental RBS support (using type sampling data from the type_fusion project).

def type: () -> Symbol

This signature was generated using 3 samples from 2 applications.

def type
  :integer
end