lib/hike/directory_index.rb in hike-0.4.0 vs lib/hike/directory_index.rb in hike-0.5.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'pathname'
+
module Hike
class DirectoryIndex
def initialize
expire_cache
end
@@ -9,23 +11,23 @@
@files = {}
true
end
def entries(dirname)
- dirname = File.expand_path(dirname)
- @entries[dirname] ||= if File.directory?(dirname)
- Dir.entries(dirname).reject do |entry|
- entry =~ /^\.\.?$/
+ dirname = Pathname.new(dirname).expand_path
+ @entries[dirname] ||= if dirname.directory?
+ dirname.entries.reject do |entry|
+ entry.to_s =~ /^\.\.?$/
end.sort
else
[]
end
end
def files(dirname)
- dirname = File.expand_path(dirname)
+ dirname = Pathname.new(dirname).expand_path
@files[dirname] ||= entries(dirname).select do |entry|
- File.file?(File.join(dirname, entry))
- end
+ dirname.join(entry).file?
+ end.map(&:to_s)
end
end
end