Module: FilePath::DirectoryMethods

Included in:
FilePath
Defined in:
lib/filepath/filepath.rb

Instance Method Summary collapse

Instance Method Details

#directories(recursive = false) ⇒ Object



793
794
795
# File 'lib/filepath/filepath.rb', line 793

def directories(recursive = false)
  entries('*', recursive).select_entries(:directory)
end

#entries(pattern = '*', recursive = false) ⇒ Object Also known as: glob



757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/filepath/filepath.rb', line 757

def entries(pattern = '*', recursive = false)
  if !self.directory?
    raise Errno::ENOTDIR.new(self)
  end

  glob = self
  glob /= '**' if recursive
  glob /= pattern

  raw_entries = Dir.glob(glob)
  entries = FilePathList.new(raw_entries)

  return entries
end

#files(recursive = false) ⇒ Object



785
786
787
# File 'lib/filepath/filepath.rb', line 785

def files(recursive = false)
  entries('*', recursive).select_entries(:file)
end

#find(pattern = nil, &block) ⇒ Object



773
774
775
776
777
778
779
780
781
782
783
# File 'lib/filepath/filepath.rb', line 773

def find(pattern = nil, &block)
  if pattern.respond_to? :to_str
    return entries(pattern, true)
  end

  if !block_given?
    block = proc { |e| e =~ pattern }
  end

  return entries('*', true).select { |e| block.call(e) }
end


789
790
791
# File 'lib/filepath/filepath.rb', line 789

def links(recursive = false)
  entries('*', recursive).select_entries(:link)
end