Sha256: 707affecae3eb476b47e5b4950a52ab5b63f356dec8bbd5e3c4b367295c6a709

Contents?: true

Size: 795 Bytes

Versions: 17

Compression:

Stored size: 795 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)
          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

            super(*predicates, type_spec: type_spec, type_rule: type_rule, **opts)
          end
        end

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
dry-schema-1.9.3 lib/dry/schema/macros/each.rb
dry-schema-1.9.2 lib/dry/schema/macros/each.rb
dry-schema-1.9.1 lib/dry/schema/macros/each.rb
dry-schema-1.9.0 lib/dry/schema/macros/each.rb
dry-schema-1.8.0 lib/dry/schema/macros/each.rb
dry-schema-1.7.1 lib/dry/schema/macros/each.rb
dry-schema-1.7.0 lib/dry/schema/macros/each.rb
dry-schema-1.6.2 lib/dry/schema/macros/each.rb
dry-schema-1.6.1 lib/dry/schema/macros/each.rb
dry-schema-1.6.0 lib/dry/schema/macros/each.rb
dry-schema-1.5.6 lib/dry/schema/macros/each.rb
dry-schema-1.5.5 lib/dry/schema/macros/each.rb
dry-schema-1.5.4 lib/dry/schema/macros/each.rb
dry-schema-1.5.3 lib/dry/schema/macros/each.rb
dry-schema-1.5.2 lib/dry/schema/macros/each.rb
dry-schema-1.5.1 lib/dry/schema/macros/each.rb
dry-schema-1.5.0 lib/dry/schema/macros/each.rb