Class: Dry::Types::Lax
- Inherits:
-
Object
- Object
- Dry::Types::Lax
- Defined in:
- lib/dry/types/lax.rb
Overview
Lax types rescue from type-related errors when constructors fail
Instance Attribute Summary collapse
- #options ⇒ Hash included from Options readonly private
- #type ⇒ Type included from Decorator readonly
Instance Method Summary collapse
-
#&(other) ⇒ Intersection, Intersection::Constrained
included
from Builder
private
Compose two types into an Intersection type.
-
#>(other) ⇒ Implication, Implication::Constrained
included
from Builder
private
Compose two types into an Implication type.
- #call(input) ⇒ Object (also: #[], #call_safe, #call_unsafe)
-
#constrained ⇒ Constrained
included
from Builder
Turn a type into a constrained type.
- #constrained? ⇒ Boolean included from Decorator
- #constrained_type ⇒ Class included from Builder private
-
#constructor(constructor = nil, **options, &block) ⇒ Constructor
(also: #append, #prepend, #>>, #<<)
included
from Builder
Define a constructor for the type.
- #constructor_type ⇒ Class included from Builder private
-
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default
included
from Builder
Turn a type into a type with a default value.
- #default? ⇒ Boolean included from Decorator
-
#enum(*values) ⇒ Enum
included
from Builder
Define an enum on top of the existing type.
-
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor
included
from Builder
Use the given value on type mismatch.
- #initialize(type) ⇒ Object included from Decorator
- #lax ⇒ Lax
-
#maybe ⇒ Maybe
included
from Builder
Turn a type into a maybe type.
-
#optional ⇒ Sum
included
from Builder
Turn a type into an optional type.
- #respond_to_missing?(meth, include_private = false) ⇒ Boolean included from Decorator
- #to_ast(meta: true) ⇒ Object
-
#to_proc ⇒ Proc
included
from Decorator
Wrap the type with a proc.
- #to_s ⇒ String (also: #inspect) included from Printable private
- #try(input, &block) {|failure| ... } ⇒ Result, Logic::Result
-
#valid?(input = Undefined) ⇒ Boolean
(also: #===)
included
from Type
private
Whether a value is a valid member of the type.
- #with(**new_options) ⇒ Type included from Options private
-
#|(other) ⇒ Sum, Sum::Constrained
included
from Builder
private
Compose two types into a Sum type.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dry::Types::Decorator
Instance Attribute Details
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
#>(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
#call(input) ⇒ Object Also known as: [], call_safe, call_unsafe
22 23 24 |
# File 'lib/dry/types/lax.rb', line 22 def call(input) type.call_safe(input) { |output = input| output } end |
#constrained ⇒ Constrained Originally defined in module Builder
Turn a type into a constrained type
#constrained? ⇒ Boolean Originally defined in module Decorator
#constrained_type ⇒ Class 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.
#constructor(constructor = nil, **options, &block) ⇒ Constructor Also known as: append, prepend, >>, << Originally defined in module Builder
Define a constructor for the type
#constructor_type ⇒ Class 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.
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default Originally defined in module Builder
Turn a type into a type with a default value
#default? ⇒ Boolean Originally defined in module Decorator
#enum(*values) ⇒ Enum Originally defined in module Builder
Define an enum on top of the existing type
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor Originally defined in module Builder
Use the given value on type mismatch
#initialize(type) ⇒ Object Originally defined in module Decorator
#respond_to_missing?(meth, include_private = false) ⇒ Boolean Originally defined in module Decorator
#to_ast(meta: true) ⇒ Object
45 46 47 |
# File 'lib/dry/types/lax.rb', line 45 def to_ast(meta: true) [:lax, type.to_ast(meta: )] end |
#to_proc ⇒ Proc Originally defined in module Decorator
Wrap the type with a proc
#to_s ⇒ String 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.
#try(input, &block) {|failure| ... } ⇒ Result, Logic::Result
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
#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.
#|(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