Sha256: d60cd9c5df6fb1ba969cc07f0e2fed44ec11178f546abb25e1c460df32158d6c

Contents?: true

Size: 849 Bytes

Versions: 4

Compression:

Stored size: 849 Bytes

Contents

# frozen_string_literal: true

require 'dry/schema/macros/value'

module Dry
  module Schema
    module Macros
      # Macro used to prepend `:filled?` predicate
      #
      # @api private
      class Filled < Value
        # @api private
        def call(*predicates, **opts, &block)
          if predicates.include?(:empty?)
            raise ::Dry::Schema::InvalidSchemaError, 'Using filled with empty? predicate is invalid'
          end

          if predicates.include?(:filled?)
            raise ::Dry::Schema::InvalidSchemaError, 'Using filled with filled? is redundant'
          end

          if opts[:type_spec]
            value(predicates[0], :filled?, *predicates[1..predicates.size - 1], **opts, &block)
          else
            value(:filled?, *predicates, **opts, &block)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-schema-1.0.3 lib/dry/schema/macros/filled.rb
dry-schema-1.0.2 lib/dry/schema/macros/filled.rb
dry-schema-1.0.1 lib/dry/schema/macros/filled.rb
dry-schema-1.0.0 lib/dry/schema/macros/filled.rb