class Dry::Schema::Macros::Schema
Macro used to specify a nested schema
@api private
Public Instance Methods
call(*args, &block)
click to toggle source
@api private
Calls superclass method
# File lib/dry/schema/macros/schema.rb, line 13 def call(*args, &block) super(*args, &nil) unless args.empty? if args.size.equal?(1) && (op = args.first).is_a?(Dry::Logic::Operations::Abstract) process_operation(op) end if block schema = define(*args, &block) import_steps(schema) trace << schema.to_rule end self end
Private Instance Methods
define(*args, &block)
click to toggle source
@api private rubocop: disable Metrics/AbcSize
# File lib/dry/schema/macros/schema.rb, line 60 def define(*args, &block) definition = schema_dsl.new(path: schema_dsl.path, &block) schema = definition.call type_schema = if array_type?(parent_type) build_array_type(parent_type, definition.strict_type_schema) elsif redefined_schema?(args) parent_type.schema(definition.types) else definition.strict_type_schema end final_type = optional? ? type_schema.optional : type_schema type(final_type) if schema.filter_rules? schema_dsl[name].filter { hash?.then(schema(schema.filter_schema)) } end schema end
hash_type()
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 37 def hash_type schema_dsl.resolve_type(:hash) end
merge_operation_types(op)
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 42 def merge_operation_types(op) op.rules.reduce({}) do |acc, rule| types = case rule when Dry::Logic::Operations::Abstract merge_operation_types(rule) when Processor rule.types else EMPTY_HASH.dup end schema_dsl.merge_types(op.class, acc, types) end end
optional?()
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 89 def optional? parent_type.optional? end
parent_type()
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 84 def parent_type schema_dsl.types[name] end
process_operation(op)
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 32 def process_operation(op) type(hash_type.schema(merge_operation_types(op))) end
redefined_schema?(args)
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 99 def redefined_schema?(args) schema? && args.first.is_a?(Processor) end
schema?()
click to toggle source
@api private
# File lib/dry/schema/macros/schema.rb, line 94 def schema? parent_type.respond_to?(:schema) end