Module: Dry::Types::Rails::TypesRegistration

Defined in:
lib/dry/types/rails/railtie.rb

Constant Summary collapse

REGISTERED_TYPES =
Concurrent::Array.new

Instance Method Summary collapse

Instance Method Details

#register_class(klass, meth = :new) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dry/types/rails/railtie.rb', line 7

def register_class(klass, meth = :new)
  super.tap do
    # Check to see if we need to remove the registered type
    autoloaded = ActiveSupport::Dependencies.will_unload?(klass)
    # ActiveSupport::Dependencies.will_unload?(klass) won't return true yet
    #   if it's the first time a constant is being autoloaded
    #   so we have to see if we're in the middle of loading a missing constants
    autoloaded |= caller(4).any? { |line| line =~ /\:in.*?new_constants_in/ }

    REGISTERED_TYPES << klass if autoloaded
  end
end