Sha256: 9ecca6d370166b2a665a0c2028d4f3ade7f66db1d5d806052d8a87537f0463c7
Contents?: true
Size: 812 Bytes
Versions: 3
Compression:
Stored size: 812 Bytes
Contents
module DataModel # Numeric type is :integer | :float | :decimal class Builtin::Numeric < Type include Errors # Arguments for this type class Arguments < Struct prop :optional, :boolean, default: false end # read a value, and validate it # @param val [Object] the value to read # @param coerce [Boolean] whether to coerce the value # @return [Array(Object, Error)] the result of reading the value def read(val, coerce: false) args = Arguments.new(type_args) err = Error.new # optional and missing if !args.optional && val.nil? err.add(missing_error(type_name)) end # when missing, return early if val.nil? return [val, err] end val, err = invoke(:or, val, params: [:integer, :float, :decimal], coerce:) # done return [val, err] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
data_model-0.6.1 | lib/data_model/builtin/numeric.rb |
data_model-0.6.0 | lib/data_model/builtin/numeric.rb |
data_model-0.5.0 | lib/data_model/builtin/numeric.rb |