Class: Dry::Schema::Processor
- Inherits:
-
Object
- Object
- Dry::Schema::Processor
- Extended by:
- Configurable, Initializer
- Includes:
- Logic::Operators, Info::SchemaMethods, JSONSchema::SchemaMethods
- Defined in:
- lib/dry/schema/processor.rb
Overview
Processes input data using objects configured within the DSL Processing is split into steps represented by `ProcessorSteps`.
Class Attribute Summary collapse
-
.definition ⇒ DSL
readonly
private
Return DSL configured via #define.
Class Method Summary collapse
-
.define(&block) ⇒ Class
Define a schema for your processor class.
-
.new(options = nil, &block) ⇒ Processor
Build a new processor object.
Instance Method Summary collapse
-
#call(input) ⇒ Result
(also: #[])
Apply processing steps to the provided input.
-
#config ⇒ Dry::Types::Config
private
Return the rules config.
-
#filter_rules? ⇒ Boolean
private
Check if there are filter rules.
-
#filter_schema ⇒ Object
private
Return filter schema.
-
#inspect ⇒ String
Return string representation.
-
#key_map ⇒ KeyMap
Return the key map.
-
#merge(other) ⇒ Processor, ...
Merge with another schema.
-
#message_compiler ⇒ MessageCompiler
private
Return the message compiler.
-
#rule_applier ⇒ Object
(also: #to_rule)
private
Return the rule applier.
-
#rules ⇒ MessageCompiler
private
Return the rules from rule applier.
-
#to_ast ⇒ Object
(also: #ast)
private
Return AST representation of the rules.
-
#to_proc ⇒ Proc
Return a proc that acts like a schema object.
-
#type_schema ⇒ Dry::Types::Safe
private
Return the type schema.
-
#types ⇒ Object
private
Return the types from the schema DSL.
- #xor(_other) ⇒ Object (also: #^)
Methods included from JSONSchema::SchemaMethods
Methods included from Info::SchemaMethods
Class Attribute Details
.definition ⇒ DSL (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.
Return DSL configured via #define
41 42 43 |
# File 'lib/dry/schema/processor.rb', line 41 def definition @definition end |
Class Method Details
.define(&block) ⇒ Class
Define a schema for your processor class
52 53 54 55 56 57 |
# File 'lib/dry/schema/processor.rb', line 52 def define(&block) @definition ||= DSL.new( processor_type: self, parent: superclass.definition, **config.to_h, &block ) self end |
.new(options = nil, &block) ⇒ Processor
Build a new processor object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dry/schema/processor.rb', line 64 def new( = nil, &block) if || block processor = super(**( || EMPTY_HASH)) yield(processor) if block processor elsif definition definition.call else raise ArgumentError, "Cannot create a schema without a definition" end end |
Instance Method Details
#call(input) ⇒ Result Also known as: []
Apply processing steps to the provided input
84 85 86 87 88 |
# File 'lib/dry/schema/processor.rb', line 84 def call(input) Result.new(input.dup, message_compiler: ) do |result| steps.call(result) end end |
#config ⇒ Dry::Types::Config
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.
Return the rules config
159 160 161 |
# File 'lib/dry/schema/processor.rb', line 159 def config @config ||= rule_applier.config end |
#filter_rules? ⇒ Boolean
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.
Check if there are filter rules
199 200 201 |
# File 'lib/dry/schema/processor.rb', line 199 def filter_rules? @filter_rules_predicate ||= schema_dsl.filter_rules? end |
#filter_schema ⇒ 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.
Return filter schema
206 207 208 |
# File 'lib/dry/schema/processor.rb', line 206 def filter_schema @filter_schema ||= schema_dsl.filter_schema end |
#inspect ⇒ String
Return string representation
122 123 124 125 126 |
# File 'lib/dry/schema/processor.rb', line 122 def inspect <<~STR.strip #<#{self.class.name} keys=#{key_map.map(&:dump)} rules=#{rules.transform_values(&:to_s)}> STR end |
#key_map ⇒ KeyMap
Return the key map
133 134 135 |
# File 'lib/dry/schema/processor.rb', line 133 def key_map steps.key_map end |
#merge(other) ⇒ Processor, ...
Merge with another schema
104 105 106 |
# File 'lib/dry/schema/processor.rb', line 104 def merge(other) schema_dsl.merge(other.schema_dsl).() end |
#message_compiler ⇒ MessageCompiler
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.
Return the message compiler
176 177 178 |
# File 'lib/dry/schema/processor.rb', line 176 def rule_applier. end |
#rule_applier ⇒ Object Also known as: to_rule
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.
Return the rule applier
149 150 151 |
# File 'lib/dry/schema/processor.rb', line 149 def rule_applier steps.rule_applier end |
#rules ⇒ MessageCompiler
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.
Return the rules from rule applier
185 186 187 |
# File 'lib/dry/schema/processor.rb', line 185 def rules rule_applier.rules end |
#to_ast ⇒ Object Also known as: ast
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.
Return AST representation of the rules
166 167 168 |
# File 'lib/dry/schema/processor.rb', line 166 def to_ast(*) rule_applier.to_ast end |
#to_proc ⇒ Proc
Return a proc that acts like a schema object
113 114 115 |
# File 'lib/dry/schema/processor.rb', line 113 def to_proc ->(input) { call(input) } end |
#type_schema ⇒ Dry::Types::Safe
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.
Return the type schema
142 143 144 |
# File 'lib/dry/schema/processor.rb', line 142 def type_schema steps.type_schema end |
#types ⇒ 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.
Return the types from the schema DSL
192 193 194 |
# File 'lib/dry/schema/processor.rb', line 192 def types schema_dsl.types end |
#xor(_other) ⇒ Object Also known as: ^
92 93 94 |
# File 'lib/dry/schema/processor.rb', line 92 def xor(_other) raise NotImplementedError, "composing schemas using `xor` operator is not supported yet" end |