Class: Dry::Validation::Rust::Schema::ProcessorHooks Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/rust/schema/processor_hooks.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

STAGES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[value_coercer].freeze

Class Method Summary collapse

Class Method Details

.apply(hooks, data) ⇒ Object

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.



35
36
37
38
39
40
41
# File 'lib/dry/validation/rust/schema/processor_hooks.rb', line 35

def self.apply(hooks, data)
  hooks.each do |hook|
    replacement = hook.call(data)
    data = replacement if replacement.is_a?(Hash)
  end
  data
end

.deep_dup(value) ⇒ Object

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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dry/validation/rust/schema/processor_hooks.rb', line 11

def self.deep_dup(value)
  case value
  when Hash
    value.each_with_object({}) do |(key, item), copy|
      copy[deep_dup(key)] = deep_dup(item)
    end
  when Array
    value.map { |item| deep_dup(item) }
  else
    value.dup
  end
rescue TypeError
  value
end

.register(hooks, name, block) ⇒ Object

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.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/dry/validation/rust/schema/processor_hooks.rb', line 26

def self.register(hooks, name, block)
  unless STAGES.include?(name)
    raise ArgumentError, "Undefined step name #{name.inspect}. Available names: #{STAGES.inspect}"
  end
  raise ArgumentError, 'processor hooks require a block' unless block

  hooks << block
end