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

Version Path
fun_with_json_api-0.0.11.1 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.11 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.10.4 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.10.3 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.10.2 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.10.1 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.10 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.9 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.8.2 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.8.1 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.8 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.7 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.6.pre.alpha.2 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.6.pre.alpha.1 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.6.1 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.6 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.5 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.4 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.3 lib/fun_with_json_api/attributes/date_attribute.rb
fun_with_json_api-0.0.2 lib/fun_with_json_api/attributes/date_attribute.rb