Sha256: d66c006460b47a2cfb55e15bac73c5188420a0c314522fc8ce525c9b1bfbc264
Contents?: true
Size: 1.11 KB
Versions: 17
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true class ReeMapper::Float < ReeMapper::AbstractType contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::TypeError) def serialize(value, role: nil) if value.is_a?(Float) value else raise ReeMapper::TypeError, 'should be a float' end end contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError) def cast(value, role: nil) if value.is_a?(Float) value elsif value.is_a?(String) begin Float(value) rescue ArgumentError => e raise ReeMapper::CoercionError, "is invalid float" end else raise ReeMapper::TypeError, "should be a float" end end contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError) def db_dump(value, role: nil) serialize(value, role: role) end contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Float).throws(ReeMapper::CoercionError, ReeMapper::TypeError) def db_load(value, role: nil) cast(value, role: role) end end
Version data entries
17 entries across 17 versions & 1 rubygems