Sha256: 9583580d1aff35dd085a4f13542fe6d137700b9ca327d9ccd792dfa191141fcc

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 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]
            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

3 entries across 3 versions & 1 rubygems

Version Path
dry-schema-0.6.0 lib/dry/schema/macros/filled.rb
dry-schema-0.5.1 lib/dry/schema/macros/filled.rb
dry-schema-0.5.0 lib/dry/schema/macros/filled.rb