Sha256: 6e433cd6b49ac1b26bc0cab315f9b5c91827f7c2a43703f6beeb043949c12799

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-0.2.0 lib/dry/schema/macros/filled.rb