Sha256: 5ac5ef4a3906fedbad141d7a6b3214afc537c9931880c933dafbe0488b085903
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 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/>. require_relative "path_rule" def parse_xoltignore(path) xoltignore_path = "#{path}/.xoltignore" return [] if !File.file?(xoltignore_path) File.readlines(xoltignore_path) .reject {|line| line == "" || line[0] == "#"} .map {|line| line.chomp} .map {|line| PathRule.new(path, line)} end module FileFinder def FileFinder.explore_folder(folder=Dir.pwd, ignore_rules=[]) files = [] ignored_paths = [".", "..", ".git", ".xoltignore", "xolti.yml", "LICENSE"] ignore_rules += parse_xoltignore(folder) Dir.glob("#{folder}/{*,.*}") .delete_if {|x| ignored_paths.include?(File.basename(x))} .each do |path| # Do NOT ignore by default ignore = :exclude if File.directory?(path) ignore_rules.each do |rule| ignore = rule.effect if rule.folder_match(path) end files += explore_folder(path, ignore_rules) if ignore == :exclude else ignore_rules.each do |rule| ignore = rule.effect if rule.file_match(path) end files << path if ignore == :exclude end end files end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xolti-0.2.0 | lib/file_finder.rb |