Permalink
Browse files

Kernel#require in 1.9 mode

  • Loading branch information...
1 parent d1ac070 commit be0509717683f198f75e283928bdc38c0f49e7b8 @Locke23rus Locke23rus committed Jan 6, 2012
Showing with 98 additions and 49 deletions.
  1. +4 −49 kernel/common/codeloader.rb
  2. +47 −0 kernel/common/codeloader18.rb
  3. +47 −0 kernel/common/codeloader19.rb
View
53 kernel/common/codeloader.rb
@@ -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.
@@ -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
View
47 kernel/common/codeloader18.rb
@@ -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
View
47 kernel/common/codeloader19.rb
@@ -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.