Class: Dry::Schema::Macros::Each Private

Inherits:
DSL
  • Object
show all
Defined in:
lib/dry/schema/macros/each.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, #primitive_inferrer

Instance Method Summary collapse

Methods inherited from DSL

#array, #custom_type?, #each, #filled, #hash, #maybe, #schema, #type

Methods inherited from Core

#new, #operation, #path, #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.



24
25
26
# File 'lib/dry/schema/macros/each.rb', line 24

def 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.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dry/schema/macros/each.rb', line 11

def value(*args, **opts, &block)
  extract_type_spec(args, set_type: false) do |*predicates, type_spec:, type_rule:|
    if type_spec && !type_spec.is_a?(Dry::Types::Type)
      type(schema_dsl.array[type_spec])
    end

    append_macro(Macros::Value) do |macro|
      macro.call(*predicates, type_spec: type_spec, type_rule: type_rule, **opts, &block)
    end
  end
end