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

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

Overview

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

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



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