Class: ReeMapper::DateTime
- Inherits:
-
AbstractType
- Object
- AbstractType
- ReeMapper::DateTime
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb', line 16 def cast(value) if value.class == DateTime value elsif value.class == Time ReeDatetime::InDefaultTimeZone.new.call(value.to_datetime) elsif value.is_a?(String) begin ReeDatetime::InDefaultTimeZone.new.call(DateTime.parse(value)) rescue ArgumentError raise ReeMapper::CoercionError.new("is invalid datetime, got `#{truncate(value.inspect)}`") end else raise ReeMapper::TypeError.new("should be a datetime, got `#{truncate(value.inspect)}`") end end |
#db_dump(value) ⇒ Object
33 34 35 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb', line 33 def db_dump(value) serialize(value) end |
#db_load(value) ⇒ Object
38 39 40 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date_time.rb', line 38 def db_load(value) cast(value) end |