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) ⇒ Ignores

Returns a new instance of Ignores.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mate/tm_properties/ignores.rb', line 7

def initialize(dir)
  @dir = dir
  @exclude = ['**/.git']
  @exclude_directories = []

  process(dir, '.', Pathname(`git config --get core.excludesfile`.strip).expand_path)
  process(dir, '.', Pathname('~/.tmignore').expand_path)

  dir.find do |path|
    if path.directory?
      %w[.gitignore .tmignore .git/info/exclude].each do |ignore_file_name|
        if (ignore_file = path + ignore_file_name).file?
          process(dir, path.relative_path_from(dir).to_s, ignore_file)
        end
      end
    end
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/mate/tm_properties/ignores.rb', line 6

def dir
  @dir
end

Instance Method Details

#linesObject



26
27
28
29
30
31
32
# File 'lib/mate/tm_properties/ignores.rb', line 26

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