Sha256: 071f0ee368475b51cd43febc1994235e237f4e4d15d37e2593800044382b2896
Contents?: true
Size: 817 Bytes
Versions: 27
Compression:
Stored size: 817 Bytes
Contents
module Scrivito module IntegerConversion INTEGER_STRING_REGEX = /\A-?\d+\z/.freeze DEFAULT_VALUE = 0 RANGE = Range.new(-(2**53 - 1), (2**53 - 1)).freeze def self.deserialize_from_backend(backend_value) case backend_value when Integer, Float, INTEGER_STRING_REGEX value = backend_value.to_i RANGE.include?(value) ? value : DEFAULT_VALUE when nil, String DEFAULT_VALUE else raise Scrivito::InternalError, "invalid value #{backend_value} (class: #{backend_value.class})" end end def self.serialize_for_backend(value, attr_name) unless RANGE.include?(value) raise ClientError.new( "Value #{value} for attribute #{attr_name} is out of range: #{RANGE}") end value end end end
Version data entries
27 entries across 27 versions & 1 rubygems