Sha256: 0d411ebc0e9aa38c26db5676252d1cd9e30668e4e7462f6614643edffc71c244
Contents?: true
Size: 667 Bytes
Versions: 2
Compression:
Stored size: 667 Bytes
Contents
module FunWithJsonApi module Attributes class DecimalAttribute < Attribute def decode(value) if value unless value.to_s =~ /[0-9]+(\.[0-9]+)?/ raise build_invalid_attribute_error(value) end BigDecimal(value.to_s) end end protected def build_invalid_attribute_error(value) payload = ExceptionPayload.new payload.detail = I18n.t('fun_with_json_api.exceptions.invalid_decimal_attribute') payload.pointer = "/data/attributes/#{name}" Exceptions::InvalidAttribute.new("Unable to parse decimal: #{value.inspect}", payload) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fun_with_json_api-0.0.14 | lib/fun_with_json_api/attributes/decimal_attribute.rb |
fun_with_json_api-0.0.13 | lib/fun_with_json_api/attributes/decimal_attribute.rb |