lib/rest_model/serialization/date.rb in rest_model-0.2.1 vs lib/rest_model/serialization/date.rb in rest_model-0.2.3
- old
+ new
@@ -1,16 +1,16 @@
class RestModel
module Serialization
class Date
- def self.serialize(value)
+ def self.serialize(value, options = {})
::Date.parse value
rescue
raise SerializationError, "value '#{value}' is an invalid date"
end
- def self.desserialize(value)
+ def self.desserialize(value, options = {})
date = value.kind_of?(::Date) ? value : ::Date.parse(value)
- format = RestModel::Configuration.date_format
+ format = options.fetch(:format, RestModel::Configuration.date_format)
format ? date.strftime(format) : date.to_s
rescue
raise SerializationError, "value '#{value}' is an invalid date"
end
end