Class: ReeMapper::Date
- Inherits:
-
AbstractType
- Object
- AbstractType
- ReeMapper::Date
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/date.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.rb', line 16 def cast(value) if value.class == Date value elsif value.class == DateTime || value.class == Time value.to_date elsif value.is_a?(String) begin Date.parse(value) rescue ArgumentError raise ReeMapper::CoercionError.new("is invalid date, got `#{truncate(value.inspect)}`") end else raise ReeMapper::TypeError.new("should be a date, 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.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.rb', line 38 def db_load(value) cast(value) end |