Sha256: b334cb335538b0230c7086e6bd19e695c43f648ce81f3ee840d2b4367e8eb627

Contents?: true

Size: 920 Bytes

Versions: 13

Compression:

Stored size: 920 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 = :strict)
        super
      end

      # @api private
      def initialize(types, namespace = :strict)
        @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

13 entries across 13 versions & 1 rubygems

Version Path
dry-schema-1.8.0 lib/dry/schema/type_registry.rb
dry-schema-1.7.1 lib/dry/schema/type_registry.rb
dry-schema-1.7.0 lib/dry/schema/type_registry.rb
dry-schema-1.6.2 lib/dry/schema/type_registry.rb
dry-schema-1.6.1 lib/dry/schema/type_registry.rb
dry-schema-1.6.0 lib/dry/schema/type_registry.rb
dry-schema-1.5.6 lib/dry/schema/type_registry.rb
dry-schema-1.5.5 lib/dry/schema/type_registry.rb
dry-schema-1.5.4 lib/dry/schema/type_registry.rb
dry-schema-1.5.3 lib/dry/schema/type_registry.rb
dry-schema-1.5.2 lib/dry/schema/type_registry.rb
dry-schema-1.5.1 lib/dry/schema/type_registry.rb
dry-schema-1.5.0 lib/dry/schema/type_registry.rb