Class: Dry::Schema::Step Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/schema/step.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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, name:, executor:, path: Path::EMPTY) ⇒ Step

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.

Returns a new instance of Step.



22
23
24
25
26
27
28
# File 'lib/dry/schema/step.rb', line 22

def initialize(type:, name:, executor:, path: Path::EMPTY)
  @type = type
  @name = name
  @executor = executor
  @path = path
  validate_name(name)
end

Instance Attribute Details

#executorObject (readonly)

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.



16
17
18
# File 'lib/dry/schema/step.rb', line 16

def executor
  @executor
end

#nameObject (readonly)

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.



10
11
12
# File 'lib/dry/schema/step.rb', line 10

def name
  @name
end

#pathObject (readonly)

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.



19
20
21
# File 'lib/dry/schema/step.rb', line 19

def path
  @path
end

#typeObject (readonly)

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.



13
14
15
# File 'lib/dry/schema/step.rb', line 13

def type
  @type
end

Instance Method Details

#call(result) ⇒ 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.



31
32
33
34
35
36
37
# File 'lib/dry/schema/step.rb', line 31

def call(result)
  scoped_result = path.equal?(Path::EMPTY) ? result : result.at(path)

  output = executor.(scoped_result)
  scoped_result.replace(output) if output.is_a?(Hash)
  output
end

#scoped(parent_path) ⇒ 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.



40
41
42
43
44
45
46
47
# File 'lib/dry/schema/step.rb', line 40

def scoped(parent_path)
  self.class.new(
    type: type,
    name: name,
    executor: executor,
    path: Path.new([*parent_path, *path])
  )
end