Class: Castkit::Types::DateTime

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

Overview

Type definition for ‘:datetime` attributes.

Handles deserialization from strings and other input into ‘DateTime` objects, and serializes `DateTime` values into ISO8601 strings.

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

`datetime :published_ad`

Instance Method Summary collapse

Methods inherited from Base

cast!, deserialize, serialize, validate!, #validate!

Instance Method Details

#deserialize(value) ⇒ ::DateTime

Deserializes the input value to a ‘DateTime` instance.

Parameters:

  • value (Object)

Returns:

  • (::DateTime)

Raises:

  • (ArgumentError)

    if parsing fails

[View source]

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

def deserialize(value)
  ::DateTime.parse(value.to_s)
end

#serialize(value) ⇒ String

Serializes a ‘DateTime` object to ISO8601 string format.

Parameters:

  • value (::DateTime)

Returns:

[View source]

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

def serialize(value)
  value.iso8601
end