class Dry::Schema::Macros::Array

Macro used to specify predicates for each element of an array

@api private

Public Instance Methods

ast(*)
Alias for: to_ast
to_ast(*) click to toggle source

@api private

# File lib/dry/schema/macros/array.rb, line 45
def to_ast(*)
  [:and, [trace.array?.to_ast, [:each, trace.to_ast]]]
end
Also aliased as: ast
value(*args, **opts, &block) click to toggle source

@api private

Calls superclass method
# File lib/dry/schema/macros/array.rb, line 13
def value(*args, **opts, &block)
  type(:array)

  extract_type_spec(*args, set_type: false) do |*predicates, type_spec:, type_rule:|
    type(schema_dsl.array[type_spec]) if type_spec

    is_hash_block = type_spec.equal?(:hash)

    if predicates.any? || opts.any? || !is_hash_block
      super(
        *predicates, type_spec: type_spec, type_rule: type_rule, **opts,
        &(is_hash_block ? nil : block)
      )
    end

    is_op = args.size.equal?(2) && args[1].is_a?(Logic::Operations::Abstract)

    if is_hash_block && !is_op
      hash(&block)
    elsif is_op
      hash = Value.new(schema_dsl: schema_dsl.new, name: name).hash(args[1])

      trace.captures.concat(hash.trace.captures)

      type(schema_dsl.types[name].of(hash.schema_dsl.types[name]))
    end
  end

  self
end