Class: TypedParams::Transformer

Inherits:
Mapper
  • Object
show all
Defined in:
lib/typed_params/transformer.rb

Instance Method Summary collapse

Methods inherited from Mapper

call, #initialize

Constructor Details

This class inherits a constructor from TypedParams::Mapper

Instance Method Details

#call(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/typed_params/transformer.rb', line 7

def call(params)
  depth_first_map(params) do |param|
    schema = param.schema

    # Ignore nil optionals when config is enabled
    unless schema.allow_nil?
      if param.value.nil? && schema.optional? && TypedParams.config.ignore_nil_optionals
        param.delete

        break
      end
    end

    schema.transforms.each do |transform|
      transform.call(param)
      break if
        param.deleted?

      # Check for nils again after transform
      unless schema.allow_nil?
        if param.value.nil? && schema.optional? && TypedParams.config.ignore_nil_optionals
          param.delete

          break
        end
      end
    end
  end
end