Class: Evilution::Integration::Loading::ConcernStateCleaner

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

Overview

Re-evaluating an ‘ActiveSupport::Concern` module raises “MultipleIncludedBlocks” because AS::Concern records the block source location on the first include/prepend call. Before a re-eval we clear the `@_included_block` / `@_prepended_block` ivar on modules whose block came from the file we’re about to re-eval.

Constant Summary collapse

IVARS =
%i[@_included_block @_prepended_block].freeze

Instance Method Summary collapse

Constructor Details

#initialize(subpath_resolver: Evilution::LoadPath::SubpathResolver.new) ⇒ ConcernStateCleaner

Returns a new instance of ConcernStateCleaner.



14
15
16
# File 'lib/evilution/integration/loading/concern_state_cleaner.rb', line 14

def initialize(subpath_resolver: Evilution::LoadPath::SubpathResolver.new)
  @subpath_resolver = subpath_resolver
end

Instance Method Details

#call(file_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/evilution/integration/loading/concern_state_cleaner.rb', line 18

def call(file_path)
  return unless defined?(ActiveSupport::Concern)

  absolute = File.expand_path(file_path)
  subpath = @subpath_resolver.call(file_path)

  ObjectSpace.each_object(Module) do |mod|
    next unless mod.singleton_class.ancestors.include?(ActiveSupport::Concern)

    clear_concern_ivars(mod, absolute, subpath)
  end
end