summaryrefslogtreecommitdiff
path: root/lib/pry/code
diff options
context:
space:
mode:
authorShannon Skipper <shannonskipper@gmail.com>2013-11-23 14:46:56 -0800
committerShannon Skipper <shannonskipper@gmail.com>2013-11-23 14:46:56 -0800
commit95110424c630c2436668ddd73a70aa2ba4289759 (patch)
treec4439aa4be1c26926658e4289d423b57ce553439 /lib/pry/code
parent3a1dad7c3fe3b9b3328e26e657ac432bc31a35fe (diff)
downloadpry-95110424c630c2436668ddd73a70aa2ba4289759.tar.gz
Refactored.
Diffstat (limited to 'lib/pry/code')
-rw-r--r--lib/pry/code/code_file.rb24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/pry/code/code_file.rb b/lib/pry/code/code_file.rb
index a7437e1d..618a66a2 100644
--- a/lib/pry/code/code_file.rb
+++ b/lib/pry/code/code_file.rb
@@ -54,31 +54,27 @@ class Pry
# @return [String] absolute path for the given `filename`.
def abs_path(filename)
find_abs_path(filename) or
- raise MethodSource::SourceNotFoundError, "Cannot open #{filename.inspect} for reading."
+ raise MethodSource::SourceNotFoundError, "Cannot open #{filename.inspect} for reading."
end
def find_abs_path(filename)
- code_path(filename).detect { |path| readable_source?(path) }.tap do |path|
- path << DEFAULT_EXT if path && !File.exist?(path)
- end
+ code_path(filename).detect { |path| readable_source?(path) }
end
+ # @param [String] path
+ # @return [Boolean] if the path, with or without the default ext,
+ # is a readable file then `true`, otherwise `false`.
def readable_source?(path)
- File.readable?(path) || File.readable?(path + DEFAULT_EXT)
+ File.readable?(path) && !File.directory?(path) or
+ File.readable?(path << DEFAULT_EXT)
end
# @return [Array] All the paths that contain code that Pry can use for its
# API's. Skips directories.
def code_path(filename)
- normalized_load_path = $LOAD_PATH.map do |path|
- File.expand_path(filename, path).tap do |p|
- p << DEFAULT_EXT if File.directory?(p)
- end
- end
-
- [ File.expand_path(filename, Dir.pwd),
- File.expand_path(filename, Pry::INITIAL_PWD),
- *normalized_load_path ]
+ [File.expand_path(filename, Dir.pwd),
+ File.expand_path(filename, Pry::INITIAL_PWD),
+ *$LOAD_PATH.map { |path| File.expand_path(filename, path) }]
end
# @param [String] filename