Module: RuxRails::RequirePatch

Included in:
Object
Defined in:
lib/rux-rails/core_ext/kernel.rb

Instance Method Summary collapse

Instance Method Details

#require(file) ⇒ Object



21
22
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
# File 'lib/rux-rails/core_ext/kernel.rb', line 21

def require(file)
  # check to see if there's a .rux file somewhere on the load path
  path = nil
  rux_file = file.end_with?('.rux') ? file : "#{file}.rux"

  if File.absolute_path(rux_file) == rux_file && File.exist?(rux_file)
    path = rux_file
  elsif rux_file.start_with?(".#{File::SEPARATOR}")
    abs_path = File.expand_path(rux_file)
    path = abs_path if File.exist?(abs_path)
  else
    $LOAD_PATH.each do |lp|
      check_path = File.expand_path(File.join(lp, rux_file))

      if File.exist?(check_path)
        path = check_path
        break
      end
    end
  end

  return super(file) unless path
  return false if $LOADED_FEATURES.include?(path)

  # 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.
  Kernel.load(path)
  $LOADED_FEATURES << path

  return true
end