Class: Dry::Schema::Macros::Array Private

Inherits:
DSL
  • Object
show all
Defined in:
lib/dry/schema/macros/array.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Macro used to specify predicates for each element of an array

Instance Attribute Summary

Attributes inherited from DSL

#chain, #predicate_inferrer

Instance Method Summary collapse

Methods inherited from DSL

#array, #each, #filled, #hash, #schema, #type

Methods inherited from Core

#new, #operation, #to_rule

Instance Method Details

#to_astObject Also known as: ast

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/dry/schema/macros/array.rb', line 32

def to_ast(*)
  [:and, [trace.array?.to_ast, [:each, trace.to_ast]]]
end

#value(*args, **opts, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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(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, **opts, &(is_hash_block ? nil : block))
    end

    hash(&block) if is_hash_block
  end

  self
end