Class: AttrTypecastable::Types::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/attr_typecastable/types/date.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #typecast

Constructor Details

This class inherits a constructor from AttrTypecastable::Types::Base

Instance Method Details

#do_typecast(value) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/attr_typecastable/types/date.rb', line 10

def do_typecast(value)
  return value if value.is_a?(::Date)

  if value.respond_to?(:to_date)
    value.to_date
  else
    raise CastError, "value does not have `to_date` method"
  end
end