class Mate::TmProperties::Ignores
Constants
- GENERATED_R
- GENERATED_SUFFIX
Attributes
dir[R]
Public Class Methods
new(dir, options)
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 9 def initialize(dir, options) @dir = dir @exclude = ['**/.git'] @exclude_directories = [] process('.', Git.excludesfile(dir)) process('.', Git.global_tmignore) if !options[:skip_info_exclude] && (git_dir = Git.git_dir(dir)) process('.', git_dir + 'info/exclude') end dir.find do |path| next unless path.lstat.directory? toplevel = dir == path if !toplevel && (path + '.git').exist? TmProperties.new(path, options).save Find.prune else relative_path = path.relative_path_from(dir).to_s Find.prune if ignore_dir?(relative_path) %w[.gitignore .tmignore].each do |ignore_file_name| process(relative_path, path + ignore_file_name) end if !toplevel && (path + '.tm_properties').exist? TmProperties.new(path, options).cleanup end end end end
Public Instance Methods
lines()
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 42 def lines escaped_dir = glob_escape(dir.to_s) [ "exclude = '#{escaped_dir}/#{glob_join(@exclude)}' #{GENERATED_SUFFIX}", "excludeDirectories = '#{escaped_dir}/#{glob_join(@exclude_directories)}' #{GENERATED_SUFFIX}", ].map{ |line| line.gsub("\r", '\r') } end
Private Instance Methods
glob_escape(string)
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 84 def glob_escape(string) string.gsub(/([\*\?\[\]\{\}])/, '\\\\\1') end
glob_join(list)
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 88 def glob_join(list) list.length == 1 ? list : "{#{list.join(',')}}" end
ignore_dir?(path)
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 52 def ignore_dir?(path) [@exclude, @exclude_directories].any? do |patterns| patterns.any? do |pattern| File.fnmatch(pattern, path, File::FNM_PATHNAME) end end end
process(subdirectory, ignore_file)
click to toggle source
# File lib/mate/tm_properties/ignores.rb, line 60 def process(subdirectory, ignore_file) return unless ignore_file && ignore_file.exist? prefix = subdirectory == '.' ? '' : glob_escape("#{subdirectory}/") ignore_file.readlines.map do |line| line.lstrip[/(.*?)(\r?\n)?$/, 1] # this strange stuff strips line, but allows mac Icon\r files to be ignored end.reject do |line| line.empty? || line =~ /^\#/ end.each do |pattern| negate = pattern.sub!(/^\!/, '') unless pattern.sub!(/^\//, '') pattern = "**/#{pattern}" end pattern = "#{prefix}#{pattern}" list = (pattern.sub!(/\/$/, '') ? @exclude_directories : @exclude) if negate list.delete(pattern) # negation only works for exact matches else list << pattern end end end