Method: Dry::Types::Schema#with_key_transform

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

#with_key_transform(proc = nil, &block) ⇒ Schema

Inject a key transformation function

Parameters:

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

Returns:

Raises:

  • (::ArgumentError)


182
183
184
185
186
187
188
189
# File 'lib/dry/types/schema.rb', line 182

def with_key_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(key_transform_fn: handle)
end