Method: Kernel#require

Defined in:
lib/rjb/extension.rb

#require(path) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rjb/extension.rb', line 46

def require(path)
  rjb_original_require(path)
rescue LoadError
  # check that it's not a jar file
  raise unless path =~ /\.jar/

  # This will maybe use the wrong jar file from a previous version of the GEM
  # puts "LOAD PATH #{$LOAD_PATH}" 
  found_path = $LOAD_PATH.reverse.find{|p| File.exist?(File.join(p,path))}
  raise unless found_path

  abs_path = File.join(found_path, path)
  # check that the file exists
  raise unless  File.exist?(abs_path)

  # try to load it using RJB
  if Rjb::loaded?
    Rjb::add_jar abs_path
  else
    Rjb::add_classpath abs_path
  end
end