Sha256: fa0c2cf1d5e5262e93f7a18ae9ec76311a797e7bab2b4579abfc31ffeeab0a18
Contents?: true
Size: 671 Bytes
Versions: 2
Compression:
Stored size: 671 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.new(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.11.3 | lib/fun_with_json_api/attributes/decimal_attribute.rb |
fun_with_json_api-0.0.11.2 | lib/fun_with_json_api/attributes/decimal_attribute.rb |