Sha256: 9c72119f383596cbfc29500cb59f7bd57117407045b01afad9eebf43b1d47e6f
Contents?: true
Size: 675 Bytes
Versions: 21
Compression:
Stored size: 675 Bytes
Contents
module FunWithJsonApi module Attributes class DateAttribute < Attribute DATE_FORMAT = '%Y-%m-%d'.freeze def call(value) Date.strptime(value, DATE_FORMAT) if value rescue ArgumentError => exception raise build_invalid_attribute_error(exception, value) end private def build_invalid_attribute_error(exception, value) payload = ExceptionPayload.new payload.detail = I18n.t('fun_with_json_api.exceptions.invalid_date_attribute') payload.pointer = "/data/attributes/#{name}" Exceptions::InvalidAttribute.new(exception.message + ": #{value.inspect}", payload) end end end end
Version data entries
21 entries across 21 versions & 1 rubygems