Method: Dry::Types::Hash#with_type_transform

Defined in:
lib/dry/types/hash.rb

#with_type_transform(proc = nil, &block) ⇒ Hash

Injects a type transformation function for building schemas

Parameters:

  • proc (#call, nil) (defaults to: nil)
  • block (#call, nil)

Returns:

Raises:

  • (::ArgumentError)
[View source]

67
68
69
70
71
72
73
74
# File 'lib/dry/types/hash.rb', line 67

def with_type_transform(proc = nil, &block)
  fn = proc || block

  raise ::ArgumentError, "a block or callable argument is required" if fn.nil?

  handle = ::Dry::Types::FnContainer.register(fn)
  with(type_transform_fn: handle)
end