class Dry::Schema::Step::Scoped

@api private

Attributes

path[R]

@api private

step[R]

@api private

Public Class Methods

new(path, step) click to toggle source

@api private

# File lib/dry/schema/step.rb, line 28
def initialize(path, step)
  @path = Path[path]
  @step = step
end

Public Instance Methods

call(result) click to toggle source

@api private

# File lib/dry/schema/step.rb, line 39
def call(result)
  result.at(path) do |scoped_result|
    output = step.(scoped_result).to_h
    target = Array(path)[0..-2].reduce(result) { |a, e| a[e] }

    target.update(path.last => output)
  end
end
scoped(new_path) click to toggle source

@api private

# File lib/dry/schema/step.rb, line 34
def scoped(new_path)
  self.class.new(Path[[*new_path, *path]], step)
end