at master 1.0 kB view raw
1# This is a shim around whatever real rbconfig.rb is in the LOAD_PATH, 2# so that RbConfig::CONFIG["ridir"] can be overridden to point to the 3# custom location of the ri docs, without the main derivation having 4# those docs in its closure. 5 6MY_PATH = File.realpath(__FILE__) 7 8candidates = $LOAD_PATH.map { |dir| File.join(dir, "rbconfig.rb") } 9 10# First, drop everything _before_ this file in the LOAD_PATH, just on 11# the off-chance somebody is composing shims like this for some reason. 12candidates.drop_while { |c| !File.exist?(c) || File.realpath(c) != MY_PATH } 13 14# Now, the wrapped rbconfig.rb is the next rbconfig.rb in the LOAD_PATH 15# that isn't this same file. (Yes, duplicate LOAD_PATH entries are a 16# thing we have to deal with.) 17next_rbconfig = candidates.find { |c| 18 File.exist?(c) && File.realpath(c) != MY_PATH 19} 20 21# Load the wrapped rbconfig.rb 22require next_rbconfig 23 24# Now we have RbConfig, and can modify it for our own ends. 25RbConfig::CONFIG["ridir"] = File.expand_path("../../../share/ri", __dir__)