Sha256: 39667ee4fd0251794323b8d27847372de55006ccd2b6ca04622575ff2c7616a2

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 Bytes

Contents

require 'dry/schema/macros/value'

module Dry
  module Schema
    module Macros
      # Macro used to specify a nested schema
      #
      # @api public
      class Schema < Value
        # @api private
        def call(*args, &block)
          super(*args) unless args.empty?

          if block
            definition = schema_dsl.new(&block)

            parent_type = schema_dsl.types[name]
            definition_schema = definition.type_schema

            schema_type =
              if parent_type.respond_to?(:of)
                parent_type.of(definition_schema)
              else
                definition_schema
              end

            final_type =
              if schema_dsl.maybe?(parent_type)
                schema_type.optional
              else
                schema_type
              end

            schema_dsl.set_type(name, final_type)

            trace << definition.to_rule
          end

          self
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-0.2.0 lib/dry/schema/macros/schema.rb