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:



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

def lax
  self
end

#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

#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