Method: Kernel#require

Defined in:
lib/onload/core_ext/kernel_zeitwerk.rb

#require(file) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/onload/core_ext/kernel_zeitwerk.rb', line 38

def require(file)
  to_load = nil

  if File.absolute_path(file) == file
    to_load = Onload.unprocessed_file_for(file)
  elsif file.start_with?(".#{File::SEPARATOR}")
    abs_path = File.expand_path(file)
    to_load = Onload.unprocessed_file_for(abs_path)
  else
    $LOAD_PATH.each do |lp|
      check_path = File.expand_path(File.join(lp, file))

      if (unprocessed_file = Onload.unprocessed_file_for(check_path))
        to_load = unprocessed_file
        break
      end
    end
  end

  if !to_load || Onload::UNLOADABLE_EXTENSIONS.include?(::File.extname(to_load))
    # This will be either Ruby's original require or bootsnap's monkeypatched
    # require in setups that use bootsnap. Lord help us with all these layers
    # of patches.
    return onload_orig_require(file)
  end

  return false if $LOADED_FEATURES.include?(to_load)

  load to_load
  $LOADED_FEATURES << to_load

  return true
end