Sha256: 7b4bb1724aa667450af953454dcb275e87db876e7505f96478ee6a065b51a58e
Contents?: true
Size: 875 Bytes
Versions: 3
Compression:
Stored size: 875 Bytes
Contents
module Taro::Types::FieldValidation # Validate the value against the field properties. This method will raise # a Taro::InputError or Taro::ResponseError if the value is not matching. def validated_value(value, for_input = true) validate_null_and_ok?(value, for_input) validate_enum_inclusion(value, for_input) value end private def validate_null_and_ok?(value, for_input) return if null || !value.nil? raise for_input ? Taro::InputError : Taro::ResponseError, <<~MSG Field #{name} is not nullable (got #{value.inspect}) MSG end def validate_enum_inclusion(value, for_input) return if enum.nil? || null && value.nil? || enum.include?(value) raise for_input ? Taro::InputError : Taro::ResponseError, <<~MSG Field #{name} has an invalid value #{value.inspect} (expected one of #{enum.inspect}) MSG end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
taro-1.4.0 | lib/taro/types/field_validation.rb |
taro-1.3.0 | lib/taro/types/field_validation.rb |
taro-1.2.0 | lib/taro/types/field_validation.rb |