Sha256: a76e8e07750b5f0745a49d46e899fa488b18710f2b833da66c4c6042478b7cea
Contents?: true
Size: 744 Bytes
Versions: 51
Compression:
Stored size: 744 Bytes
Contents
module Scrivito module FloatConversion FLOAT_STRING_REGEX = /\A-?\d+(\.\d+)?\z/.freeze def self.deserialize_from_backend(backend_value) case backend_value when Integer, Float, FLOAT_STRING_REGEX value = backend_value.to_f value.finite? ? value : nil when nil, String nil else raise Scrivito::InternalError, "invalid value #{backend_value} (class: #{backend_value.class})" end end def self.serialize_for_backend(value, attr_name) serialized_value = value.to_f unless serialized_value.finite? raise ClientError.new( "Value #{value} for attribute #{attr_name} is not supported.") end value end end end
Version data entries
51 entries across 51 versions & 1 rubygems