Sha256: bead9b2a6e9e970dc21fb224ef242b4c189b076b6f791cdade59f137b3a718fc

Contents?: true

Size: 677 Bytes

Versions: 4

Compression:

Stored size: 677 Bytes

Contents

module FunWithJsonApi
  module Attributes
    class DateAttribute < Attribute
      DATE_FORMAT = '%Y-%m-%d'.freeze

      def decode(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

4 entries across 4 versions & 1 rubygems

Version Path
fun_with_json_api-0.0.14 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.13 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.11.3 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.11.2 lib/fun_with_json_api/attributes/date_attribute.rb