Class: Morf::Casters::DateCaster
- Inherits:
-
Object
- Object
- Morf::Casters::DateCaster
- Defined in:
- lib/morf/casters/date_caster.rb
Class Method Summary collapse
Class Method Details
.cast(value, attr_name, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/morf/casters/date_caster.rb', line 4 def self.cast(value, attr_name, = {}) if value.is_a?(Date) value elsif value.is_a?(String) begin Date.parse(value) rescue ArgumentError => e raise Morf::Errors::CastingError, "is invalid date" end else raise Morf::Errors::CastingError, "should be a date" end end |