Class: Castkit::Types::String
Overview
Type definition for :string attributes.
Coerces any input to a string using to_s, and validates that the resulting value is a String. Supports optional format validation via a :format option (Regexp or Proc).
This class is used internally by Castkit when an attribute is defined with:
`string :id`
Instance Method Summary collapse
-
#deserialize(value) ⇒ String
Deserializes the value by coercing it to a string using
to_s. -
#serialize(value) ⇒ String
Serializes the value as-is.
-
#validate!(value, options: {}, context: {}) ⇒ void
Validates the value is a
Stringand optionally matches a format.
Methods inherited from Base
cast!, deserialize, serialize, validate!
Instance Method Details
#deserialize(value) ⇒ String
Deserializes the value by coercing it to a string using to_s.
20 21 22 |
# File 'lib/castkit/types/string.rb', line 20 def deserialize(value) value.to_s end |
#serialize(value) ⇒ String
Serializes the value as-is.
28 29 30 |
# File 'lib/castkit/types/string.rb', line 28 def serialize(value) value end |
#validate!(value, options: {}, context: {}) ⇒ void
This method returns an undefined value.
Validates the value is a String and optionally matches a format.
39 40 41 |
# File 'lib/castkit/types/string.rb', line 39 def validate!(value, options: {}, context: {}) Castkit::Validators::StringValidator.call(value, options: , context: context) end |