Class: Castkit::Types::Date
Overview
Type definition for :date attributes.
Handles deserialization from strings and other input into Date objects, and serializes Date values into ISO8601 strings.
This class is used internally by Castkit when an attribute is defined with:
`date :published_on`
Instance Method Summary collapse
-
#deserialize(value) ⇒ ::Date
Deserializes the input value to a
Dateinstance. -
#serialize(value) ⇒ String
Serializes a
Dateobject to ISO8601 string format.
Methods inherited from Base
cast!, deserialize, serialize, validate!, #validate!
Instance Method Details
#deserialize(value) ⇒ ::Date
Deserializes the input value to a Date instance.
21 22 23 |
# File 'lib/castkit/types/date.rb', line 21 def deserialize(value) ::Date.parse(value.to_s) end |
#serialize(value) ⇒ String
Serializes a Date object to ISO8601 string format.
29 30 31 |
# File 'lib/castkit/types/date.rb', line 29 def serialize(value) value.iso8601 end |