Sha256: 65b7f2d75b19012a51d5e1d7e96b207ae055ccd7bba200632f1ca9791fa5a91f

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

require 'dry/schema/macros/value'

module Dry
  module Schema
    module Macros
      # Macro used to prepend `:filled?` predicate
      #
      # @api public
      class Filled < Value
        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].equal?(true)
            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

2 entries across 2 versions & 1 rubygems

Version Path
dry-schema-0.4.0 lib/dry/schema/macros/filled.rb
dry-schema-0.3.0 lib/dry/schema/macros/filled.rb