Class: AnnotateRb::ModelAnnotator::ZeitwerkClassGetter
- Inherits:
-
Object
- Object
- AnnotateRb::ModelAnnotator::ZeitwerkClassGetter
- Defined in:
- lib/annotate_rb/model_annotator/zeitwerk_class_getter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Constant?
Attempts to return the model class constant (e.g. User) defined in the model file can return
nilif the file does not define the constant. -
#initialize(file, options) ⇒ ZeitwerkClassGetter
constructor
A new instance of ZeitwerkClassGetter.
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, ) @file = file @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, ) new(file, ).call end |
Instance Method Details
#call ⇒ Constant?
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.
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.(@file) loader = ::Rails.autoloaders.main if supports_cpath? constant_using_cpath(loader) else constant(loader) end end |