Class: Filters::GitIgnore

Inherits:
Object
  • Object
show all
Defined in:
lib/filters/git_ignore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patterns = []) ⇒ GitIgnore

Returns a new instance of GitIgnore.



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

def initialize(patterns = [])


  @globs = [] 
  @negative_globs = []

  patterns.each do |pattern|

    pattern.strip!

    next if /^\#/.match(pattern)
   
    if /^\\\#/.match(pattern)
      add_globs Sftp::Sync::GlobBuilder.new(pattern.slice(1,pattern.length - 1))
    else
       add_globs Sftp::Sync::GlobBuilder.new(pattern)
    end

  end

end

Instance Attribute Details

#globsObject (readonly)

Returns the value of attribute globs.



8
9
10
# File 'lib/filters/git_ignore.rb', line 8

def globs
  @globs
end

#negative_globsObject (readonly)

Returns the value of attribute negative_globs.



8
9
10
# File 'lib/filters/git_ignore.rb', line 8

def negative_globs
  @negative_globs
end

Instance Method Details

#match(filename) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/filters/git_ignore.rb', line 33

def match(filename)


  @globs.each do |glob|
    if File.fnmatch(glob, filename,  File::FNM_PATHNAME) #  removeing path thing? (or be mor specific w/ glob)


      @negative_globs.each do |n_glob|
        return false if File.fnmatch(n_glob, filename,  File::FNM_PATHNAME)
      end

      return true 

    end
  end
  false
end