Module: Filepath::SearchMethods

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

Instance Method Summary collapse

Instance Method Details

#directories(recursive = false) ⇒ Object



957
958
959
# File 'lib/filepath/filepath.rb', line 957

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

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



921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'lib/filepath/filepath.rb', line 921

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



949
950
951
# File 'lib/filepath/filepath.rb', line 949

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

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



937
938
939
940
941
942
943
944
945
946
947
# File 'lib/filepath/filepath.rb', line 937

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

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

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


953
954
955
# File 'lib/filepath/filepath.rb', line 953

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