File: predicate_registry.rb

package info (click to toggle)
ruby-dry-types 1.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 504 kB
  • sloc: ruby: 3,059; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'dry/logic/predicates'

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

      # @api private
      attr_reader :has_predicate

      # @api private
      def initialize(predicates = Logic::Predicates)
        @predicates = predicates
        @has_predicate = ::Kernel.instance_method(:respond_to?).bind(@predicates)
      end

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

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