Module: Kernel

Defined in:
lib/derailed_benchmarks/core_ext/kernel_require.rb

Overview

Monkey patch kernel to ensure that all ‘require` calls call the same method

Constant Summary collapse

REQUIRE_STACK =
[]

Class Method Summary collapse

Class Method Details

.original_requireObject



18
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 18

alias_method :original_require, :require

.original_require_relativeObject



19
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 19

alias_method :original_require_relative, :require_relative

.require(file) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 21

def require(file)
  measure_memory_impact(file) do |file|
    # "source_annotation_extractor" is deprecated in Rails 6
    # # if we don't skip the library it leads to a crash
    # next if file == "rails/source_annotation_extractor" && Rails.version >= '6.0'
    original_require(file)
  end
end

.require_relative(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 30

def require_relative(file)
  if Pathname.new(file).absolute?
    require file
  else
    require File.expand_path("../#{file}", caller_locations(1, 1)[0].absolute_path)
  end
end