Sha256: 879d3e086b2184095ccb8c84fb449a7f19c28a153ae8c75052b6d3a5cb1e9925

Contents?: true

Size: 761 Bytes

Versions: 10

Compression:

Stored size: 761 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:|
            if type_spec && !type_spec.is_a?(Dry::Types::Type)
              type(schema_dsl.array[type_spec])
            end

            super(*predicates, type_spec: type_spec, **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

10 entries across 10 versions & 1 rubygems

Version Path
dry-schema-1.4.3 lib/dry/schema/macros/each.rb
dry-schema-1.4.2 lib/dry/schema/macros/each.rb
dry-schema-1.4.1 lib/dry/schema/macros/each.rb
dry-schema-1.4.0 lib/dry/schema/macros/each.rb
dry-schema-1.3.4 lib/dry/schema/macros/each.rb
dry-schema-1.3.3 lib/dry/schema/macros/each.rb
dry-schema-1.3.2 lib/dry/schema/macros/each.rb
dry-schema-1.3.1 lib/dry/schema/macros/each.rb
dry-schema-1.3.0 lib/dry/schema/macros/each.rb
dry-schema-1.2.0 lib/dry/schema/macros/each.rb