Module: ActiveSupport::Dependencies

Defined in:
lib/brick/extensions.rb

Class Method Summary collapse

Class Method Details

._brick_autoload_module!Object

%%% Probably a little more targeted than other approaches we’ve taken thusfar This happens before the whole parent check



1204
# File 'lib/brick/extensions.rb', line 1204

alias _brick_autoload_module! autoload_module!

.autoload_module!(*args) ⇒ Object



1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
# File 'lib/brick/extensions.rb', line 1205

def autoload_module!(*args)
  into, const_name, qualified_name, path_suffix = args
  if (base_class_name = ::Brick.config.sti_namespace_prefixes&.fetch("::#{into.name}::", nil))
    base_class_name = "::#{base_class_name}" unless base_class_name.start_with?('::')
  end
  if (base_class = base_class_name&.constantize)
    ::Brick.sti_models[qualified_name] = { base: base_class }
    # Build subclass and place it into the specially STI-namespaced module
    into.const_set(const_name.to_sym, klass = Class.new(base_class))
    # %%% used to also have:  autoload_once_paths.include?(base_path) ||
    autoloaded_constants << qualified_name unless autoloaded_constants.include?(qualified_name)
    klass
  elsif (base_class = ::Brick.config.sti_namespace_prefixes&.fetch("::#{const_name}", nil)&.constantize)
    begin
      # Attempt to find an existing implementation for this subclass
      base_class.module_parent.const_get(const_name)
    rescue
      # Build subclass and place it in the same module as its parent
      base_class.module_parent.const_set(const_name.to_sym, klass = Class.new(base_class))
    end
  else
    _brick_autoload_module!(*args)
  end
end