Sha256: 91bcd0f491a23ac33fe3ce167ed2427fe989f2954fa50d5e3433de69993826c7

Contents?: true

Size: 897 Bytes

Versions: 11

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

require 'dry/types/container'

module Dry
  module Types
    # Internal container for constructor functions used by the built-in types
    #
    # @api private
    class FnContainer
      # @api private
      def self.container
        @container ||= Container.new
      end

      # @api private
      def self.register(function = Dry::Core::Constants::Undefined, &block)
        fn = Dry::Core::Constants::Undefined.default(function, block)
        fn_name = register_name(fn)
        container.register(fn_name, fn) unless container.key?(fn_name)
        fn_name
      end

      # @api private
      def self.[](fn_name)
        if container.key?(fn_name)
          container[fn_name]
        else
          fn_name
        end
      end

      # @api private
      def self.register_name(function)
        "fn_#{function.object_id}"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-types-1.4.0/lib/dry/types/fn_container.rb
dry-types-1.4.0 lib/dry/types/fn_container.rb
dry-types-1.3.1 lib/dry/types/fn_container.rb
dry-types-1.3.0 lib/dry/types/fn_container.rb
dry-types-1.2.2 lib/dry/types/fn_container.rb
dry-types-1.2.1 lib/dry/types/fn_container.rb
dry-types-1.2.0 lib/dry/types/fn_container.rb
dry-types-1.1.1 lib/dry/types/fn_container.rb
dry-types-1.1.0 lib/dry/types/fn_container.rb
dry-types-1.0.1 lib/dry/types/fn_container.rb
dry-types-1.0.0 lib/dry/types/fn_container.rb