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
Return DSL
configured via define
@return [DSL] @api private
Public Class Methods
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
Build a new processor object
@return [Processor]
@api public
# 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
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
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
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
Return filter schema
@api private
# File lib/dry/schema/processor.rb, line 201 def filter_schema @filter_schema ||= schema_dsl.filter_schema end
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
Return the key map
@return [KeyMap]
@api public
# File lib/dry/schema/processor.rb, line 135 def key_map steps.key_map end
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
Return the message compiler
@return [MessageCompiler]
@api private
# File lib/dry/schema/processor.rb, line 178 def message_compiler rule_applier.message_compiler end
Return the rule applier
@api private
# File lib/dry/schema/processor.rb, line 151 def rule_applier steps.rule_applier end
Return the rules from rule applier
@return [MessageCompiler]
@api private
# File lib/dry/schema/processor.rb, line 187 def rules rule_applier.rules end
Return AST representation of the rules
@api private
# File lib/dry/schema/processor.rb, line 168 def to_ast(*) rule_applier.to_ast end
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
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
@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