Sha256: f8436b9491f3201b62e59828e9576237cf5c6256435e1dad6cc904664a1dd148

Contents?: true

Size: 921 Bytes

Versions: 9

Compression:

Stored size: 921 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

9 entries across 9 versions & 1 rubygems

Version Path
dry-schema-1.1.0 lib/dry/schema/type_registry.rb
dry-schema-1.0.3 lib/dry/schema/type_registry.rb
dry-schema-1.0.2 lib/dry/schema/type_registry.rb
dry-schema-1.0.1 lib/dry/schema/type_registry.rb
dry-schema-1.0.0 lib/dry/schema/type_registry.rb
dry-schema-0.6.0 lib/dry/schema/type_registry.rb
dry-schema-0.5.1 lib/dry/schema/type_registry.rb
dry-schema-0.5.0 lib/dry/schema/type_registry.rb
dry-schema-0.4.0 lib/dry/schema/type_registry.rb