Module: Dry::Mutations::DSL::Schema

Defined in:
lib/dry/mutations/dsl/schema.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#schema(*args, input_processor: nil, type: :form, **options, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dry/mutations/dsl/schema.rb', line 5

def schema *args, input_processor: nil, type: :form, **options, &block
  case args.count
  when 0, 1
    schema, = args
    @schema ||= patched_schema(schema) \
            || derived_schema(input_processor: input_processor, type: type, **options, &block)
    return @schema unless block_given?
    @schema = Validation.Schema(@schema, **@schema.options, &block)
  when 2 # explicit dry schema given
    name = args.first
    current = @current # closure scope

    schema do
      Utils.smart_send(__send__(current, name), :schema, args.last, **options, &block)
    end
    define_method(name) { Utils::Hash(@inputs[name]) }
  end
end