Class: Mate::TmProperties::Ignores

Inherits:
Object
  • Object
show all
Defined in:
lib/mate/tm_properties/ignores.rb

Constant Summary collapse

GENERATED_SUFFIX =
'## GENERATED ##'
GENERATED_R =
/^exclude(?:Directories)? = .* #{Regexp.escape(GENERATED_SUFFIX)}$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options) ⇒ Ignores

Returns a new instance of Ignores.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/mate/tm_properties/ignores.rb', line 8

def dir
  @dir
end

Instance Method Details

#linesObject



42
43
44
45
46
47
48
# 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