class Dry::Schema::ProcessorSteps
Steps for the Dry::Schema::Processor
There are 4 main steps:
1. `key_coercer` - Prepare input hash using a key map 2. `filter_schema` - Apply pre-coercion filtering rules (optional step, used only when `filter` was used) 3. `value_coercer` - Apply value coercions based on type specifications 4. `rule_applier` - Apply rules
@see Processor
@api public
Public Instance Methods
[](name)
click to toggle source
Returns step by name
@param [Symbol] name The step name
@api public
# File lib/dry/schema/processor_steps.rb, line 67 def [](name) steps[name] end
[]=(name, value)
click to toggle source
Sets step by name
@param [Symbol] name The step name
@api public
# File lib/dry/schema/processor_steps.rb, line 76 def []=(name, value) steps[name] = Step.new(type: :core, name: name, executor: value) end
after(name, &block)
click to toggle source
Add passed block before mentioned step
@param [Symbol] name The step name
@return [ProcessorSteps]
@api public
# File lib/dry/schema/processor_steps.rb, line 87 def after(name, &block) after_steps[name] ||= EMPTY_ARRAY.dup after_steps[name] << Step.new(type: :after, name: name, executor: block) self end
before(name, &block)
click to toggle source
Add passed block before mentioned step
@param [Symbol] name The step name
@return [ProcessorSteps]
@api public
# File lib/dry/schema/processor_steps.rb, line 100 def before(name, &block) before_steps[name] ||= EMPTY_ARRAY.dup before_steps[name] << Step.new(type: :before, name: name, executor: block) self end
call(result)
click to toggle source
Executes steps and callbacks in order
@param [Result] result
@return [Result]
@api public
# File lib/dry/schema/processor_steps.rb, line 37 def call(result) STEPS_IN_ORDER.each do |name| before_steps[name]&.each { |step| step&.(result) } steps[name]&.(result) after_steps[name]&.each { |step| step&.(result) } end result end
import_callbacks(path, other)
click to toggle source
@api private
# File lib/dry/schema/processor_steps.rb, line 128 def import_callbacks(path, other) other.before_steps.each do |name, steps| (before_steps[name] ||= []).concat(steps.map { |step| step.scoped(path) }) end other.after_steps.each do |name, steps| (after_steps[name] ||= []).concat(steps.map { |step| step.scoped(path) }) end end
key_map()
click to toggle source
@api private
# File lib/dry/schema/processor_steps.rb, line 53 def key_map @key_map ||= self[:key_coercer].executor.key_map end
merge(other)
click to toggle source
Stacks callback steps and returns new ProcessorSteps
instance
@param [ProcessorSteps] other
@return [ProcessorSteps]
@api public
# File lib/dry/schema/processor_steps.rb, line 113 def merge(other) ProcessorSteps.new( before_steps: merge_callbacks(before_steps, other.before_steps), after_steps: merge_callbacks(after_steps, other.after_steps) ) end
merge_callbacks(left, right)
click to toggle source
@api private
# File lib/dry/schema/processor_steps.rb, line 121 def merge_callbacks(left, right) left.merge(right) do |_key, oldval, newval| oldval + newval end end
rule_applier()
click to toggle source
@api private
# File lib/dry/schema/processor_steps.rb, line 48 def rule_applier @rule_applier ||= steps[:rule_applier].executor end
type_schema()
click to toggle source
@api private
# File lib/dry/schema/processor_steps.rb, line 58 def type_schema @type_schema ||= steps[:value_coercer].executor.type_schema end