Sha256: 1d22736d412147997a676772cf39f7b8388da1c91eee800e4e709b8f9bab4455

Contents?: true

Size: 763 Bytes

Versions: 8

Compression:

Stored size: 763 Bytes

Contents

require 'dry/types/container'

module Dry
  module Types
    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

8 entries across 8 versions & 1 rubygems

Version Path
dry-types-0.14.1 lib/dry/types/fn_container.rb
dry-types-0.15.0 lib/dry/types/fn_container.rb
dry-types-0.14.0 lib/dry/types/fn_container.rb
dry-types-0.13.4 lib/dry/types/fn_container.rb
dry-types-0.13.3 lib/dry/types/fn_container.rb
dry-types-0.13.2 lib/dry/types/fn_container.rb
dry-types-0.13.1 lib/dry/types/fn_container.rb
dry-types-0.13.0 lib/dry/types/fn_container.rb