mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Support 'require_relative' in rubies less than v1.9.2
This commit is contained in:
parent
ce79fcfa0f
commit
6fdeed596e
1 changed files with 21 additions and 0 deletions
21
lib/require_relative.rb
Normal file
21
lib/require_relative.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# require_relative was introduced in 1.9.2. This makes it
|
||||||
|
# available to younger rubies. It trys hard to not re-require
|
||||||
|
# files.
|
||||||
|
|
||||||
|
unless Kernel.respond_to?( :require_relative )
|
||||||
|
module Kernel
|
||||||
|
def require_relative( path )
|
||||||
|
desired_path = File.expand_path( '../' + path.to_str, caller[0] )
|
||||||
|
shortest = desired_path
|
||||||
|
$:.each do |path|
|
||||||
|
path += '/'
|
||||||
|
if desired_path.index( path ) == 0
|
||||||
|
candidate = desired_path.sub( path, '' )
|
||||||
|
shortest = candidate if candidate.size < shortest.size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
require shortest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue