lib/rice_bubble/attributes/datetime.rb in rice_bubble-0.1.2 vs lib/rice_bubble/attributes/datetime.rb in rice_bubble-0.2.0
- old
+ new
@@ -1,28 +1,21 @@
module RiceBubble
class Attributes
class Datetime < Base
- def valid?(value)
- return false unless valid_datetime?(value)
-
- value.respond_to?(:to_datetime)
+ def call(value, path: '')
+ super(coerce(value), path:)
end
def coerce(value)
- return nil unless valid_datetime?(value)
-
- value.respond_to?(:to_datetime) ? value.to_datetime : value
+ if !value.respond_to?(:to_datetime) || value.is_a?(::Date)
+ value
+ else
+ value.to_datetime
+ end
end
- private
-
- def valid_datetime?(value)
- case value
- when ::Time then true
- when ::DateTime then true
- when ::Date then false
- else value.respond_to?(:to_datetime)
- end
+ def valid_types
+ [::Time, ::DateTime]
end
end
end
end