Sha256: c01e6506a4bbbd9250e3ac93001a77070bd9beb5e21bc5ffae9d2ba0ec92e576

Contents?: true

Size: 884 Bytes

Versions: 5

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

require "dry/types/type"
require "dry/schema/macros/dsl"

module Dry
  module Schema
    module Macros
      # Macro used to specify predicates for each element of an array
      #
      # @api private
      class Each < DSL
        # @api private
        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

        # @api private
        def to_ast(*)
          [:each, trace.to_ast]
        end
        alias_method :ast, :to_ast
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-schema-1.10.6 lib/dry/schema/macros/each.rb
dry-schema-1.10.5 lib/dry/schema/macros/each.rb
dry-schema-1.10.4 lib/dry/schema/macros/each.rb
dry-schema-1.10.2 lib/dry/schema/macros/each.rb
dry-schema-1.10.1 lib/dry/schema/macros/each.rb