Sha256: 6a519d9cccae7bfcaf4abedcaf955ee9679331c7f3b6aab16259dd78b680dac8

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# file_finder.rb
# Copyright (C) RĂ©mi Even 2016
#
# This file is part of Xolti.
#
# Xolti is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Xolti is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
# TODO : handle "folder/file" patterns
def parse_xoltignore(path)
	xoltignorePath = "#{path}/.xoltignore"
	return [] if !File.file?(xoltignorePath)
	File.readlines(xoltignorePath).reject {|line| line == "" || line[0] == "#"}.map {|line| line.chomp}
end

module FileFinder
	def FileFinder.explore_folder(folder=Dir.pwd, ignoreRules=[])
		fileAcc = []
		ignoredPaths = [".", "..", ".git", ".xoltignore", "xolti.yml", "LICENSE"]
		ignoreRules += parse_xoltignore(folder)

		Dir.glob("#{folder}/{*,.*}")
			.delete_if {|x| ignoredPaths.include?(File.basename(x))}
			.delete_if do |x|
				basename = File.basename(x)
				toIgnore = false
				ignoreRules.each do |rule|
					if (rule[0] == "!" && File.fnmatch(rule[1..-1], basename))
						toIgnore = false
					elsif (File.fnmatch(rule, basename))
						toIgnore = true
					end
				end
				toIgnore
			end
			.each do |path|
				if File.directory?(path)
					fileAcc += explore_folder(path, ignoreRules)
				else
					fileAcc << path
				end
			end

		fileAcc
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xolti-0.1.1 lib/file_finder.rb