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

Attributes included from Decorator

#type

Attributes included from Options

#options

Instance Method Summary collapse

Methods included from Printable

#to_s

Methods included from Builder

#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #maybe, #optional, #|

Methods included from Decorator

#constrained?, #default?, #initialize, #respond_to_missing?, #to_proc

Methods included from Options

#initialize, #with

Methods included from Type

#valid?

Dynamic Method Handling

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

Instance Method Details

#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

#laxLax

Returns:



48
# File 'lib/dry/types/lax.rb', line 48

def lax = self

#to_ast(meta: true) ⇒ Object

See Also:



43
# File 'lib/dry/types/lax.rb', line 43

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

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

Parameters:

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

Yield Parameters:

  • failure (Failure)

Yield Returns:

Returns:



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

def try(input, &) = type.try(input, &)