Class: Farce::Internal::DryTypes::AtomType

Inherits:
CollectionType show all
Defined in:
lib/farce/integrations/dry_types.rb

Overview

An Atom type that validates or coerces its initial contents.

Instance Attribute Summary

Attributes inherited from CollectionType

#source

Dry Types Integration collapse

Methods inherited from CollectionType

#call, #constrained?, #default?, #inspect, #meta, #name, #optional?, #primitive?, #pristine, #to_ast, #to_proc, #try, #valid?, #with

Instance Method Details

#of(value_type) ⇒ AtomType

Apply a dry type to the initial value before Atom construction.

Later writes use the ordinary Farce Atom API and are not checked by this type.

Parameters:

  • value_type (Dry::Types::Type) —

    The initial value type.

Returns:

  • (AtomType) —

    A new typed Atom constructor.

Raises:

  • (ArgumentError) —

    If value_type is not a dry type.



327
328
329
330
331
# File 'lib/farce/integrations/dry_types.rb', line 327

def of(value_type)
  raise ArgumentError, "Atom.of requires a dry type" unless value_type.is_a?(::Dry::Types::Type)

  self.class.new(value_type, kind:, configuration:)
end