Class: AnnotateRb::ModelAnnotator::ZeitwerkClassGetter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options) ⇒ ZeitwerkClassGetter

Returns a new instance of ZeitwerkClassGetter.



12
13
14
15
# File 'lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb', line 12

def initialize(file, options)
  @file = file
  @options = options
end

Class Method Details

.call(file, options) ⇒ Object



7
8
9
# File 'lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb', line 7

def call(file, options)
  new(file, options).call
end

Instance Method Details

#callConstant?

Returns Attempts to return the model class constant (e.g. User) defined in the model file can return ‘nil` if the file does not define the constant.

Returns:

  • (Constant, nil)

    Attempts to return the model class constant (e.g. User) defined in the model file can return ‘nil` if the file does not define the constant.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb', line 19

def call
  return unless defined?(::Zeitwerk)

  @absolute_file_path = File.expand_path(@file)
  loader = ::Rails.autoloaders.main

  if supports_cpath?
    constant_using_cpath(loader)
  else
    constant(loader)
  end
end