Sha256: f5534a9f6a84ee1efce0a83df54df7e60fe284c2fe63c66bffda350216b9dca4
Contents?: true
Size: 1.13 KB
Versions: 17
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true class ReeMapper::Integer < ReeMapper::AbstractType contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError) def serialize(value, role: nil) if value.is_a? Integer value else raise ReeMapper::TypeError, 'should be an integer' end end contract(Any , Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]]=> Integer).throws(ReeMapper::CoercionError, ReeMapper::TypeError) def cast(value, role: nil) if value.is_a?(Integer) value elsif value.is_a?(String) begin Integer(value) rescue ArgumentError => e raise ReeMapper::CoercionError, "is invalid integer" end else raise ReeMapper::TypeError, "should be an integer" end end contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).throws(ReeMapper::TypeError) def db_dump(value, role: nil) serialize(value, role: role) end contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Integer).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