Sha256: ea8987685307521af9d4a093ac2862efe67666edbd0027d583ae34740953807b

Contents?: true

Size: 609 Bytes

Versions: 4

Compression:

Stored size: 609 Bytes

Contents

module FunWithJsonApi
  module Attributes
    class IntegerAttribute < FunWithJsonApi::Attribute
      def decode(value)
        Integer(value.to_s) if value
      rescue ArgumentError => exception
        raise build_invalid_attribute_error(exception)
      end

      private

      def build_invalid_attribute_error(exception)
        payload = ExceptionPayload.new
        payload.detail = I18n.t('fun_with_json_api.exceptions.invalid_integer_attribute')
        payload.pointer = "/data/attributes/#{name}"
        Exceptions::InvalidAttribute.new(exception.message, 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/integer_attribute.rb
fun_with_json_api-0.0.13 lib/fun_with_json_api/attributes/integer_attribute.rb
fun_with_json_api-0.0.11.3 lib/fun_with_json_api/attributes/integer_attribute.rb
fun_with_json_api-0.0.11.2 lib/fun_with_json_api/attributes/integer_attribute.rb