class Dry::Schema::Macros::DSL

@api public
Macro specialization used within the DSL

def append_macro(macro_type)

Other tags:
    Api: - private
def append_macro(macro_type)
  macro = macro_type.new(schema_dsl: schema_dsl, name: name)
  yield(macro)
  if chain
    trace << macro
    self
  else
    macro
  end
end

def array(*args, &block)

Other tags:
    Api: - public

Returns:
  • (Macros::Core) -

Other tags:
    Example: a list of hashes -
    Example: a list of strings -
def array(*args, &block)
  append_macro(Macros::Array) do |macro|
    macro.value(*args, &block)
  end
end

def custom_type?

Other tags:
    Api: - private
def custom_type?
  schema_dsl.custom_type?(name)
end

def each(*args, &block)

Other tags:
    Api: - public

Returns:
  • (Macros::Core) -

Other tags:
    Example: a list of hashes -
    Example: a list of strings -
def each(*args, &block)
  append_macro(Macros::Each) do |macro|
    macro.value(*args, &block)
  end
end

def extract_type_spec(*args, nullable: false, set_type: true)

Other tags:
    Api: - private
def extract_type_spec(*args, nullable: false, set_type: true)
  type_spec = args[0] unless schema_or_predicate?(args[0])
  predicates = Array(type_spec ? args[1..-1] : args)
  type_rule = nil
  if type_spec
    resolved_type = resolve_type(type_spec, nullable)
    if type_spec.is_a?(::Array)
      type_rule = type_spec.map { |ts| new(chain: false).value(ts) }.reduce(:|)
    else
      type_predicates = predicate_inferrer[resolved_type]
      predicates.replace(type_predicates + predicates) unless type_predicates.empty?
      return self if predicates.empty?
    end
  end
  type(resolved_type) if set_type && resolved_type
  if type_rule
    yield(*predicates, type_spec: nil, type_rule: type_rule)
  else
    yield(*predicates, type_spec: type_spec, type_rule: nil)
  end
end

def filled(*args, &block)

Other tags:
    Api: - public

Returns:
  • (Macros::Core) -

Other tags:
    Example: with a type spec and a predicate -
    Example: with a type spec -
def filled(*args, &block)
  append_macro(Macros::Filled) do |macro|
    macro.call(*args, &block)
  end
end

def hash(*args, &block)

Other tags:
    Api: - public
def hash(*args, &block)
  append_macro(Macros::Hash) do |macro|
    macro.call(*args, &block)
  end
end

def resolve_type(type_spec, nullable)

Other tags:
    Api: - private
def resolve_type(type_spec, nullable)
  resolved = schema_dsl.resolve_type(type_spec)
  if type_spec.is_a?(::Array) || !nullable || resolved.optional?
    resolved
  else
    schema_dsl.resolve_type([:nil, resolved])
  end
end

def schema(*args, &block)

Other tags:
    Api: - public

Returns:
  • (Macros::Core) -
def schema(*args, &block)
  append_macro(Macros::Schema) do |macro|
    macro.call(*args, &block)
  end
end

def schema_or_predicate?(arg)

Other tags:
    Api: - private
def schema_or_predicate?(arg)
  arg.is_a?(Dry::Schema::Processor) ||
    arg.is_a?(Symbol) &&
      arg.to_s.end_with?(QUESTION_MARK)
end

def type(spec)

Other tags:
    Api: - public

Returns:
  • (Macros::Key) -

Parameters:
  • spec (Symbol, Array, Dry::Types::Type) --
def type(spec)
  schema_dsl.set_type(name, spec)
  self
end

def value(*predicates, &block)

Other tags:
    Api: - public

Returns:
  • (Macros::Core) -

Other tags:
    Example: with a block -
    Example: with a predicate with and without arguments -
    Example: with a predicate with arguments -
    Example: with a predicate -

Parameters:
  • predicate_opts (Hash) --
  • predicates (Array) --

Overloads:
  • value(*predicates, **predicate_opts)
def value(*predicates, &block)
  append_macro(Macros::Value) do |macro|
    macro.call(*predicates, &block)
  end
end