Class: Pk::IgnoreFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pk/ignore_file.rb

Constant Summary collapse

PKIGNORE_NAMES =
%w(pkignore .pkignore).freeze

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ IgnoreFile

Returns a new instance of IgnoreFile.



5
6
7
8
9
10
11
12
13
14
# File 'lib/pk/ignore_file.rb', line 5

def initialize(path)
  @ignore_list = PKIGNORE_NAMES.dup
  PKIGNORE_NAMES.each do |filename|
    file = File.expand_path(File.join(path, filename))
    if File.exist? file
      @ignore_list = @ignore_list + File.open(file, 'r').read.split("\n")
      break
    end
  end
end

Instance Method Details

#ignore_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/pk/ignore_file.rb', line 16

def ignore_file?(filename)
  ignore = false
  @ignore_list.each do |ignore_pattern|
    if File.fnmatch(ignore_pattern, filename, File::FNM_PATHNAME)
      ignore = true
      break
    end
  end
  ignore
end