Class: Mate::Tmproj::Ignores
- Inherits:
-
Object
- Object
- Mate::Tmproj::Ignores
- 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
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#file_pattern ⇒ Object
readonly
Returns the value of attribute file_pattern.
-
#folder_pattern ⇒ Object
readonly
Returns the value of attribute folder_pattern.
Instance Method Summary collapse
- #file_r ⇒ Object
- #folder_r ⇒ Object
- #ignore?(path) ⇒ Boolean
-
#initialize(dir) ⇒ Ignores
constructor
A new instance of Ignores.
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).) process(dir, Pathname('~/.tmignore').) 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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
11 12 13 |
# File 'lib/mate/tmproj/ignores.rb', line 11 def dir @dir end |
#file_pattern ⇒ Object (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_pattern ⇒ Object (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_r ⇒ Object
41 42 43 |
# File 'lib/mate/tmproj/ignores.rb', line 41 def file_r "^#{Regexp.escape(dir.to_s)}/(?:#{file_pattern.join('|')})$" end |
#folder_r ⇒ Object
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
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 |