module DataModel # Boolean type class Builtin::Boolean < Type include Errors # Arguments for the boolean 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) err = Error.new if val.nil? err.add(missing_error(type_name)) return [val, err] end if coerce case val when "true" val = true when "false" val = false end end if !val.is_a?(TrueClass) && !val.is_a?(FalseClass) err.add(type_error(type_name, val)) return [val, err] end return [val, err] end end end