Class: Aws::Record::Marshalers::DateTimeMarshaler
- Inherits:
-
Object
- Object
- Aws::Record::Marshalers::DateTimeMarshaler
- Defined in:
- lib/aws-record/record/marshalers/date_time_marshaler.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ DateTimeMarshaler
constructor
A new instance of DateTimeMarshaler.
- #serialize(raw_value) ⇒ Object
- #type_cast(raw_value) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ DateTimeMarshaler
Returns a new instance of DateTimeMarshaler.
9 10 11 12 |
# File 'lib/aws-record/record/marshalers/date_time_marshaler.rb', line 9 def initialize(opts = {}) @formatter = opts[:formatter] || Iso8601Formatter @use_local_time = opts[:use_local_time] ? true : false end |
Instance Method Details
#serialize(raw_value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aws-record/record/marshalers/date_time_marshaler.rb', line 23 def serialize(raw_value) datetime = type_cast(raw_value) if datetime.nil? nil elsif datetime.is_a?(::DateTime) @formatter.format(datetime) else msg = "expected a DateTime value or nil, got #{datetime.class}" raise ArgumentError, msg end end |
#type_cast(raw_value) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/aws-record/record/marshalers/date_time_marshaler.rb', line 14 def type_cast(raw_value) value = _format(raw_value) if !@use_local_time && value.is_a?(::DateTime) value.new_offset(0) else value end end |