Class: AnnotateRb::EagerLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/annotate_rb/eager_loader.rb

Overview

Not sure what this does just yet

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/annotate_rb/eager_loader.rb', line 7

def call(options)
  options[:require].count > 0 && options[:require].each { |path| require path }

  if defined?(::Zeitwerk)
    # Delegate to Zeitwerk to load stuff as needed
    #   (Supports both Rails and non-Rails applications)
  elsif defined?(::Rails::Application)
    klass = ::Rails::Application.send(:subclasses).first
    klass.eager_load!
  else
    model_files = ModelAnnotator::ModelFilesGetter.call(options)
    model_files&.each do |model_file|
      require File.join(*model_file)
    end
  end
end