Sha256: ebf6c70b2ad07acd34a108e9b7ee7eb9cb7811d2d30c0e3354a65e4cb8a65920

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Dry
  module Types
    # Common Type module denoting an object is a Type
    #
    # @api public
    module Type
      extend ::Dry::Core::Deprecations[:"dry-types"]

      deprecate(:safe, :lax)

      # Whether a value is a valid member of the type
      #
      # @return [Boolean]
      #
      # @api private
      def valid?(input = Undefined)
        call_safe(input) { return false }
        true
      end
      # Anything can be coerced matches
      alias_method :===, :valid?

      # Apply type to a value
      #
      # @overload call(input = Undefined)
      #   Possibly unsafe coercion attempt. If a value doesn't
      #   match the type, an exception will be raised.
      #
      #   @param [Object] input
      #   @return [Object]
      #
      # @overload call(input = Undefined)
      #   When a block is passed, {#call} will never throw an exception on
      #   failed coercion, instead it will call the block.
      #
      #   @param [Object] input
      #   @yieldparam [Object] output Partially coerced value
      #   @return [Object]
      #
      # @api public
      def call(input = Undefined, &block)
        if block_given?
          call_safe(input, &block)
        else
          call_unsafe(input)
        end
      end
      alias_method :[], :call
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-types-1.7.2 lib/dry/types/type.rb
dry-types-1.7.1 lib/dry/types/type.rb
dry-types-1.7.0 lib/dry/types/type.rb
dry-types-1.6.1 lib/dry/types/type.rb
dry-types-1.6.0 lib/dry/types/type.rb