Skip to content

Commit

Permalink
Kernel#require in 1.9 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Locke23rus committed Jan 6, 2012
1 parent d1ac070 commit be05097
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 49 deletions.
53 changes: 4 additions & 49 deletions kernel/common/codeloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,59 +243,12 @@ def qualified_path?(path)
path[0] == ?/ or path.prefix?("./") or path.prefix?("../")
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

@feature = path

if qualified_path? path
return false unless loadable? path
else
return false unless path = search_load_path(path, loading)
path = "./#{path}" unless qualified_path? path
end

@file_path = path
@load_path = File.expand_path path

return true
end

# Called directly by #load. Either resolves the path passed to Kernel#load
# to a specific file or raises a LoadError.
def resolve_load_path
load_error unless verify_load_path @path, true
end

# Combines +directory+, +name+, and +extension+ to check if the result is
# #loadable?. If it is, sets +@type+, +@feature+, +@load_path+, and
# +@file_path+ and returns true. See #intialize for a description of the
# instance variables.
def check_path(directory, name, extension, type)
file = "#{name}#{extension}"
path = "#{directory}/#{file}"
return false unless loadable? path

@type = type
@feature = file
@load_path = path
if qualified_path? path
@file_path = path
else
@file_path = "./#{path}"
end

return true
end

# Searches $LOAD_PATH for a file named +name+, appending ".rb" and the
# platform's shared library file extension in that order to locate an
# existing file. Returns true if a file is found. Used by #require only.
Expand Down Expand Up @@ -367,8 +320,10 @@ def resolve_require_path
end

if @type
return false if CodeLoader.feature_provided? @path
return true if verify_load_path @path
if verify_load_path @path
return false if CodeLoader.feature_provided?(@path) or CodeLoader.feature_provided?(@feature)
return true
end
else
if verify_require_path(@path)
return false if CodeLoader.feature_provided? @feature
Expand Down
47 changes: 47 additions & 0 deletions kernel/common/codeloader18.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,52 @@ def search_load_path(name, loading)

return nil
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

@feature = path

if qualified_path? path
return false unless loadable? path
else
return false unless path = search_load_path(path, loading)
path = "./#{path}" unless qualified_path? path
end

@file_path = path
@load_path = File.expand_path path

return true
end

# Combines +directory+, +name+, and +extension+ to check if the result is
# #loadable?. If it is, sets +@type+, +@feature+, +@load_path+, and
# +@file_path+ and returns true. See #intialize for a description of the
# instance variables.
def check_path(directory, name, extension, type)
file = "#{name}#{extension}"
path = "#{directory}/#{file}"
return false unless loadable? path

@type = type
@feature = file
@load_path = path
if qualified_path? path
@file_path = path
else
@file_path = "./#{path}"
end

return true
end
end
end
47 changes: 47 additions & 0 deletions kernel/common/codeloader19.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,52 @@ def self.require_relative(name, scope)
raise LoadError.new "Something is wrong in trying to get relative path"
end
end

# Main logic for converting a name to an actual file to load. Used by
# #load and by #require when the file extension is provided.
#
# Expands any #home_path? to an absolute path. Then either checks whether
# an absolute path is #loadable? or searches for a loadable file matching
# name in $LOAD_PATH.
#
# Returns true if a loadable file is found, otherwise returns false.
def verify_load_path(path, loading=false)
path = File.expand_path path if home_path? path

if qualified_path? path
return false unless loadable? path
else
return false unless path = search_load_path(path, loading)
path = "./#{path}" unless qualified_path? path
end

@file_path = path
path = File.expand_path path
@feature = path
@load_path = path

return true
end

# Combines +directory+, +name+, and +extension+ to check if the result is
# #loadable?. If it is, sets +@type+, +@feature+, +@load_path+, and
# +@file_path+ and returns true. See #intialize for a description of the
# instance variables.
def check_path(directory, name, extension, type)
file = "#{name}#{extension}"
path = "#{directory}/#{file}"
return false unless loadable? path

@type = type
@feature = path
@load_path = path
if qualified_path? path
@file_path = path
else
@file_path = "./#{path}"
end

return true
end
end
end

0 comments on commit be05097

Please sign in to comment.