Class: Dry::Types::Lax

Inherits:
Object
  • Object
show all
Includes:
Builder, Decorator, Printable, Type
Defined in:
lib/dry/types/lax.rb

Overview

Lax types rescue from type-related errors when constructors fail

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dry::Types::Decorator

Instance Attribute Details

#optionsHash (readonly) Originally defined in module Options

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

#typeType (readonly) Originally defined in module Decorator

Returns:

Instance Method Details

#&(other) ⇒ Intersection, Intersection::Constrained Originally defined in module Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compose two types into an Intersection type

Parameters:

Returns:

#>(other) ⇒ Implication, Implication::Constrained Originally defined in module Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compose two types into an Implication type

Parameters:

Returns:

#call(input) ⇒ Object Also known as: [], call_safe, call_unsafe

Parameters:

  • input (Object)

Returns:

  • (Object)


22
23
24
# File 'lib/dry/types/lax.rb', line 22

def call(input)
  type.call_safe(input) { |output = input| output }
end

#constrainedConstrained Originally defined in module Builder

Turn a type into a constrained type

Parameters:

Returns:

#constrained?Boolean Originally defined in module Decorator

Returns:

  • (Boolean)

#constrained_typeClass Originally defined in module Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Class)

#constructor(constructor = nil, **options, &block) ⇒ Constructor Also known as: append, prepend, >>, << Originally defined in module Builder

Define a constructor for the type

Parameters:

  • constructor (#call, nil) (defaults to: nil)
  • options (Hash)
  • block (#call, nil)

Returns:

#constructor_typeClass Originally defined in module Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Class)

#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default Originally defined in module Builder

Turn a type into a type with a default value

Parameters:

  • input (Object) (defaults to: Undefined)
  • block (#call, nil)
  • [Boolean] (Hash)

    a customizable set of options

Returns:

Raises:

#default?Boolean Originally defined in module Decorator

Returns:

  • (Boolean)

#enum(*values) ⇒ Enum Originally defined in module Builder

Define an enum on top of the existing type

Parameters:

Returns:

#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor Originally defined in module Builder

Use the given value on type mismatch

Parameters:

  • value (Object) (defaults to: Undefined)
  • fallback (#call, nil)
  • [Boolean] (Hash)

    a customizable set of options

Returns:

#initialize(type) ⇒ Object Originally defined in module Decorator

Parameters:

#laxLax

Returns:



52
53
54
# File 'lib/dry/types/lax.rb', line 52

def lax
  self
end

#maybeMaybe Originally defined in module Builder

Turn a type into a maybe type

Returns:

#optionalSum Originally defined in module Builder

Turn a type into an optional type

Returns:

#respond_to_missing?(meth, include_private = false) ⇒ Boolean Originally defined in module Decorator

Parameters:

  • meth (Symbol)
  • include_private (Boolean) (defaults to: false)

Returns:

  • (Boolean)

#to_ast(meta: true) ⇒ Object

See Also:



45
46
47
# File 'lib/dry/types/lax.rb', line 45

def to_ast(meta: true)
  [:lax, type.to_ast(meta: meta)]
end

#to_procProc Originally defined in module Decorator

Wrap the type with a proc

Returns:

  • (Proc)

#to_sString Also known as: inspect Originally defined in module Printable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

#try(input, &block) {|failure| ... } ⇒ Result, Logic::Result

Parameters:

  • input (Object)
  • block (#call, nil)

Yield Parameters:

  • failure (Failure)

Yield Returns:

Returns:



38
39
40
# File 'lib/dry/types/lax.rb', line 38

def try(input, &block)
  type.try(input, &block)
end

#valid?(input = Undefined) ⇒ Boolean Also known as: === Originally defined in module Type

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether a value is a valid member of the type

Returns:

  • (Boolean)

#with(**new_options) ⇒ Type Originally defined in module Options

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • new_options (Hash)

Returns:

#|(other) ⇒ Sum, Sum::Constrained Originally defined in module Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compose two types into a Sum type

Parameters:

Returns: