Class: Mate::Tmproj::Ignores

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

Constant Summary collapse

BINARY_EXTENSIONS =
[
%w[jpe?g png gif psd], # images
%w[zip tar t?(?:g|b)z], # archives
%w[mp3 mov], # media
%w[log tmp swf fla pdf]
DOUBLE_ASTERISK_R =

other

'(?:.+/)?'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Ignores

Returns a new instance of Ignores.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mate/tmproj/ignores.rb', line 12

def initialize(dir)
  @dir = dir
  @file_pattern = ["#{DOUBLE_ASTERISK_R}.+\\.(?:#{BINARY_EXTENSIONS.flatten.join('|')})"]
  @folder_pattern = ["#{DOUBLE_ASTERISK_R}.git"]

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

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/mate/tmproj/ignores.rb', line 11

def dir
  @dir
end

#file_patternObject (readonly)

Returns the value of attribute file_pattern.



11
12
13
# File 'lib/mate/tmproj/ignores.rb', line 11

def file_pattern
  @file_pattern
end

#folder_patternObject (readonly)

Returns the value of attribute folder_pattern.



11
12
13
# File 'lib/mate/tmproj/ignores.rb', line 11

def folder_pattern
  @folder_pattern
end

Instance Method Details

#file_rObject



41
42
43
# File 'lib/mate/tmproj/ignores.rb', line 41

def file_r
  "^#{Regexp.escape(dir.to_s)}/(?:#{file_pattern.join('|')})$"
end

#folder_rObject



44
45
46
# File 'lib/mate/tmproj/ignores.rb', line 44

def folder_r
  "^#{Regexp.escape(dir.to_s)}/(?:#{folder_pattern.join('|')})$"
end

#ignore?(path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/mate/tmproj/ignores.rb', line 32

def ignore?(path)
  case
  when path.file?
    path.to_s =~ /#{file_r}/
  when path.directory?
    path.to_s =~ /#{folder_r}/
  end
end