Sha256: 9f5d598c1501c5a3568375e651aa33cf72cfd0609a67304a86f2add916f01afa

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

require 'pathname'

module Hike
  class DirectoryIndex
    def initialize
      expire_cache
    end

    def expire_cache
      @entries = {}
      @files = {}
      true
    end

    def entries(dirname)
      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 = Pathname.new(dirname).expand_path
      @files[dirname] ||= entries(dirname).select do |entry|
        dirname.join(entry).file?
      end.map(&:to_s)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hike-0.5.1 lib/hike/directory_index.rb
hike-0.5.0 lib/hike/directory_index.rb