Module: Onload::KernelRequirePatch

Included in:
Object
Defined in:
lib/onload/core_ext/kernel.rb

Instance Method Summary collapse

Instance Method Details

#require(file) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/onload/core_ext/kernel.rb', line 23

def require(file)
  # check to see if there's an unprocessed file somewhere on the load path
  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[-1]].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

  return super(file) unless to_load
  return super(file) if Onload::UNLOADABLE_EXTENSIONS.include?(::File.extname(to_load))
  return false if $LOADED_FEATURES.include?(to_load)

  # Must call the Kernel.load class method here because that's the one
  # activesupport doesn't mess with, and in fact the one activesupport
  # itself uses to actually load files. In case you were curious,
  # activesupport redefines Object#load and Object#require i.e. the
  # instance versions that get inherited by all other objects. Yeah,
  # it's pretty awful stuff. Although honestly we're not much better lol.
  Kernel.load(to_load)
  $LOADED_FEATURES << to_load

  return true
end