lib/nrser/types/type.rb
# Check that a `value` satisfies the type.
# 
# @see #test?
# 
# @return [Object]
#   The value itself.
# 
# @raise [NRSER::Types::CheckError]
#   If the value does not satisfy this type.
# 
Check that a `value` satisfies the type.
Check that a ` value ` satisfies the type .
def check! value, &on_error
    return value if test? value
    if on_error
      response = begin
        case on_error.arity
        when 0
          on_error.call
        else
          on_error.call type: self, value: value
        end
      rescue StandardError => error
        error
      end
      case response
      when nil
      when ::StandardError
        raise response if response.is_a?( CheckError )
        logger.error \
          "`&on_error` must raise a {NRSER::Types::CheckError}, " +
          "received #{ response.class }",
          response
      else
        logger.error \
          "`&on_error` must return {NRSER::Types::CheckError} or `nil`",
          received: response,
          backtrace: Thread.current.backtrace
      end
    end
    raise CheckError.new \
      type: self,
      value: value
  end
def check! value , & on_error return value if test? value if on_error response = begin case on_error . arity when 0 on_error . call else on_error . call type : self , value : value end rescue StandardError => error error end case response when nil when :: StandardError raise response if response . is_a? ( CheckError ) logger . error "`&on_error` must raise a {NRSER::Types::CheckError}, " + "received #{ response.class }" , response else logger . error "`&on_error` must return {NRSER::Types::CheckError} or `nil`" , received : response , backtrace : Thread . current . backtrace end end raise CheckError . new type : self , value : value end
Check that a `value` satisfies the type.
Check that a ` value ` satisfies the type .
# success case # pass
The value itself.
The value itself .
Object
[NRSER::Types::CheckError] If the value does not satisfy this type.
[ NRSER :: Types :: CheckError ] If the value does not satisfy this type .
value
<not_specific>
on_error
<not_specific>
see
None