Class: Castkit::Types::Integer
- 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
-
#deserialize(value) ⇒ Integer
Deserializes the input value to an Integer.
-
#serialize(value) ⇒ Integer
Serializes the Integer value.
-
#validate!(value, options: {}, context: {}) ⇒ void
Validates the Integer value using Castkit’s IntegerValidator.
Methods inherited from Base
cast!, deserialize, serialize, validate!
Instance Method Details
#deserialize(value) ⇒ Integer
Deserializes the input value to an Integer.
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.
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:`.
41 42 43 |
# File 'lib/castkit/types/integer.rb', line 41 def validate!(value, options: {}, context: {}) Castkit::Validators::IntegerValidator.call(value, options: , context: context) end |