Class: Evilution::Integration::Loading::ConstantPinner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/integration/loading/constant_pinner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defeat Zeitwerk's re-autoload hook when we re-eval a file in place. Walking the source AST for top-level class/module names and calling const_get on each tells Zeitwerk "this constant is loaded" so our re-eval does not lose state (e.g. @_included_block) to a follow-up autoload.

Instance Method Summary collapse

Constructor Details

#initialize(constant_names: Evilution::AST::ConstantNames.new) ⇒ ConstantPinner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConstantPinner.



11
12
13
# File 'lib/evilution/integration/loading/constant_pinner.rb', line 11

def initialize(constant_names: Evilution::AST::ConstantNames.new)
  @constant_names = constant_names
end

Instance Method Details

#call(source) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
19
20
21
22
23
# File 'lib/evilution/integration/loading/constant_pinner.rb', line 15

def call(source)
  names = @constant_names.call(source)
  names.each do |name|
    Object.const_get(name) if Object.const_defined?(name, false)
  rescue NameError # :nodoc:
    nil
  end
  names
end