class Dry::Schema::Processor

Processes input data using objects configured within the DSL Processing is split into steps represented by `ProcessorSteps`.

@see ProcessorSteps @see Params @see JSON

@api public

Attributes

definition[R]

Return DSL configured via define

@return [DSL] @api private

Public Class Methods

define(&block) click to toggle source

Define a schema for your processor class

@see Schema#define @see Schema#Params @see Schema#JSON

@return [Class]

@api public

# File lib/dry/schema/processor.rb, line 54
def define(&block)
  @definition ||= DSL.new(
    processor_type: self, parent: superclass.definition, **config.to_h, &block
  )
  self
end
new(options = nil) { |processor| ... } click to toggle source

Build a new processor object

@return [Processor]

@api public

Calls superclass method
# File lib/dry/schema/processor.rb, line 66
def new(options = nil, &block)
  if options || block
    processor = super(**(options || EMPTY_HASH))
    yield(processor) if block
    processor
  elsif definition
    definition.call
  else
    raise ArgumentError, "Cannot create a schema without a definition"
  end
end

Public Instance Methods

[](input)
Alias for: call
^(_other)
Alias for: xor
ast(*)
Alias for: to_ast
call(input) click to toggle source

Apply processing steps to the provided input

@param [Hash] input

@return [Result]

@api public

# File lib/dry/schema/processor.rb, line 86
def call(input)
  Result.new(input.dup, message_compiler: message_compiler) do |result|
    steps.call(result)
  end
end
Also aliased as: []
config() click to toggle source

Return the rules config

@return [Dry::Types::Config]

@api private

# File lib/dry/schema/processor.rb, line 161
def config
  @config ||= rule_applier.config
end
filter_rules?() click to toggle source

Check if there are filter rules

@api private

# File lib/dry/schema/processor.rb, line 194
def filter_rules?
  @filter_rules_predicate ||= schema_dsl.filter_rules?
end
filter_schema() click to toggle source

Return filter schema

@api private

# File lib/dry/schema/processor.rb, line 201
def filter_schema
  @filter_schema ||= schema_dsl.filter_schema
end
inspect() click to toggle source

Return string represntation

@return [String]

@api public

# File lib/dry/schema/processor.rb, line 124
      def inspect
        <<~STR.strip
          #<#{self.class.name} keys=#{key_map.map(&:dump)} rules=#{rules.map { |k, v| [k, v.to_s] }.to_h}>
        STR
      end
key_map() click to toggle source

Return the key map

@return [KeyMap]

@api public

# File lib/dry/schema/processor.rb, line 135
def key_map
  steps.key_map
end
merge(other) click to toggle source

Merge with another schema

@param [Processor] other

@return [Processor, Params, JSON]

@api public

# File lib/dry/schema/processor.rb, line 106
def merge(other)
  schema_dsl.merge(other.schema_dsl).()
end
message_compiler() click to toggle source

Return the message compiler

@return [MessageCompiler]

@api private

# File lib/dry/schema/processor.rb, line 178
def message_compiler
  rule_applier.message_compiler
end
rule_applier() click to toggle source

Return the rule applier

@api private

# File lib/dry/schema/processor.rb, line 151
def rule_applier
  steps.rule_applier
end
Also aliased as: to_rule
rules() click to toggle source

Return the rules from rule applier

@return [MessageCompiler]

@api private

# File lib/dry/schema/processor.rb, line 187
def rules
  rule_applier.rules
end
to_ast(*) click to toggle source

Return AST representation of the rules

@api private

# File lib/dry/schema/processor.rb, line 168
def to_ast(*)
  rule_applier.to_ast
end
Also aliased as: ast
to_proc() click to toggle source

Return a proc that acts like a schema object

@return [Proc]

@api public

# File lib/dry/schema/processor.rb, line 115
def to_proc
  ->(input) { call(input) }
end
to_rule()
Alias for: rule_applier
type_schema() click to toggle source

Return the type schema

@return [Dry::Types::Safe]

@api private

# File lib/dry/schema/processor.rb, line 144
def type_schema
  steps.type_schema
end
xor(_other) click to toggle source

@api public

# File lib/dry/schema/processor.rb, line 94
def xor(_other)
  raise NotImplementedError, "composing schemas using `xor` operator is not supported yet"
end
Also aliased as: ^