Class: Castkit::Types::Integer

Inherits:
Base
  • Object
show all
Defined in:
lib/castkit/types/integer.rb

Overview

Type definition for ‘:integer` attributes.

Handles deserialization from raw input (e.g., strings, floats) to Integer, applies optional numeric validation rules (e.g., ‘min`, `max`), and returns the value unchanged during serialization.

This class is used internally by Castkit when an attribute is defined with:

`integer :count`

Instance Method Summary collapse

Methods inherited from Base

cast!, deserialize, serialize, validate!

Instance Method Details

#deserialize(value) ⇒ Integer

Deserializes the input value to an Integer.

Parameters:

  • value (Object)

Returns:



21
22
23
# File 'lib/castkit/types/integer.rb', line 21

def deserialize(value)
  value.to_i
end

#serialize(value) ⇒ Integer

Serializes the Integer value.

Parameters:

Returns:



29
30
31
# File 'lib/castkit/types/integer.rb', line 29

def serialize(value)
  value
end

#validate!(value, options: {}, context: {}) ⇒ void

This method returns an undefined value.

Validates the Integer value using Castkit’s IntegerValidator.

Supports options like ‘min:` and `max:`.

Parameters:

  • value (Object)
  • options (Hash) (defaults to: {})

    validation options

  • context (Symbol, String) (defaults to: {})

    attribute context for error messages



41
42
43
# File 'lib/castkit/types/integer.rb', line 41

def validate!(value, options: {}, context: {})
  Castkit::Validators::IntegerValidator.call(value, options: options, context: context)
end