Sha256: 21d9ee959a094d26008d26d67d2cbecbf96242d79fda20c8061b7e4efe13450a

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

require 'dry/schema/constants'
require 'dry/schema/types'

module Dry
  module Schema
    # A simple wrapper around Dry::Types registry
    #
    # This is used internally by specialized processor sub-classes
    #
    # @api private
    class TypeRegistry
      # @api private
      attr_reader :types

      # @api private
      attr_reader :namespace

      # @api private
      def self.new(types = Dry::Types, namespace = :nominal)
        super
      end

      # @api private
      def initialize(types, namespace = :nominal)
        @types = types
        @namespace = namespace
      end

      # @api private
      def namespaced(ns)
        self.class.new(types, ns)
      end

      # @api private
      def [](name)
        key = [namespace, name].compact.join(DOT)

        type = types.registered?(key) ? types[key] : types[name.to_s]
        type
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-schema-1.3.2 lib/dry/schema/type_registry.rb
dry-schema-1.3.1 lib/dry/schema/type_registry.rb
dry-schema-1.3.0 lib/dry/schema/type_registry.rb
dry-schema-1.2.0 lib/dry/schema/type_registry.rb