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(name, type = nil, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dry/types/rails/railtie.rb', line 7 def register(name, type = nil, &block) return super unless type return if TypesRegistration::REGISTERED_TYPES.include?(name) super.tap do # Check to see if we need to remove the registered type autoloaded = ActiveSupport::Dependencies.will_unload?(type) # 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.any? { |line| line =~ /\:in.*?new_constants_in/ } TypesRegistration::REGISTERED_TYPES << name if autoloaded end end |