Sha256: d2a211a50625abdb6cf80b6d70ede4e46a7a68ce3b21ae85e3c8df9bb52bb7d6

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 Bytes

Contents

require 'dry/logic/predicates'

module Dry
  module Schema
    # A registry with predicate objects from `Dry::Logic::Predicates`
    #
    # @api private
    class PredicateRegistry
      # @api private
      attr_reader :predicates

      # @api private
      def initialize(predicates = Dry::Logic::Predicates)
        @predicates = predicates
      end

      # @api private
      def [](name)
        predicates[name]
      end

      # @api private
      def key?(name)
        predicates.respond_to?(name)
      end

      # @api private
      def arg_list(name, *values)
        predicate = self[name]

        predicate
          .parameters
          .map(&:last)
          .zip(values + Array.new(predicate.arity - values.size, Undefined))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-schema-0.2.0 lib/dry/schema/predicate_registry.rb
dry-schema-0.1.1 lib/dry/schema/predicate_registry.rb
dry-schema-0.1.0 lib/dry/schema/predicate_registry.rb